title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Scrape a dynamic website
206,855
<p>What is the best method to scrape a dynamic website where most of the content is generated by what appears to be ajax requests? I have previous experience with a Mechanize, BeautifulSoup, and python combo, but I am up for something new.</p> <p>--Edit-- For more detail: I'm trying to scrape the CNN <a href="http://...
12
2008-10-15T23:04:13Z
216,143
<p>The best solution that I found was to use Firebug to monitor XmlHttpRequests, and then to use a script to resend them.</p>
7
2008-10-19T07:38:59Z
[ "python", "ajax", "screen-scraping", "beautifulsoup" ]
Scrape a dynamic website
206,855
<p>What is the best method to scrape a dynamic website where most of the content is generated by what appears to be ajax requests? I have previous experience with a Mechanize, BeautifulSoup, and python combo, but I am up for something new.</p> <p>--Edit-- For more detail: I'm trying to scrape the CNN <a href="http://...
12
2008-10-15T23:04:13Z
216,161
<p>Probably the easiest way is to use IE webbrowser control in C# (or any other language). You have access to all the stuff inside browser out of the box + you dont need to care about cookies, SSL and so on.</p>
1
2008-10-19T08:03:11Z
[ "python", "ajax", "screen-scraping", "beautifulsoup" ]
Scrape a dynamic website
206,855
<p>What is the best method to scrape a dynamic website where most of the content is generated by what appears to be ajax requests? I have previous experience with a Mechanize, BeautifulSoup, and python combo, but I am up for something new.</p> <p>--Edit-- For more detail: I'm trying to scrape the CNN <a href="http://...
12
2008-10-15T23:04:13Z
219,990
<p>There is a bit of a learning curve, but tools like Pamie (Python) or Watir (Ruby) will let you latch into the IE web browser and get at the elements. This turns out to be easier than Mechanize and other HTTP level tools since you don't have to emulate the browser, you just ask the browser for the html elements. And ...
2
2008-10-20T21:22:06Z
[ "python", "ajax", "screen-scraping", "beautifulsoup" ]
Scrape a dynamic website
206,855
<p>What is the best method to scrape a dynamic website where most of the content is generated by what appears to be ajax requests? I have previous experience with a Mechanize, BeautifulSoup, and python combo, but I am up for something new.</p> <p>--Edit-- For more detail: I'm trying to scrape the CNN <a href="http://...
12
2008-10-15T23:04:13Z
642,138
<p>i found the IE Webbrowser control have all kinds of quirks and workarounds that would justify some high quality software to take care of all those inconsistencies, layered around the shvwdoc.dll api and mshtml and provide a framework. </p>
1
2009-03-13T10:47:39Z
[ "python", "ajax", "screen-scraping", "beautifulsoup" ]
Scrape a dynamic website
206,855
<p>What is the best method to scrape a dynamic website where most of the content is generated by what appears to be ajax requests? I have previous experience with a Mechanize, BeautifulSoup, and python combo, but I am up for something new.</p> <p>--Edit-- For more detail: I'm trying to scrape the CNN <a href="http://...
12
2008-10-15T23:04:13Z
8,997,123
<p>The first question I have: can you confirm that the site absolutely doesn't work without Javascript? You'd be surprised how many sites are still usable if you turn javascript off. You'll probably be directed to a slightly different set of urls. </p>
0
2012-01-25T02:21:13Z
[ "python", "ajax", "screen-scraping", "beautifulsoup" ]
Help with <key> event in python Entry widget
206,916
<p>I'm writing some code in python and I'm having trouble when trying to retrieve content of an Entry widget. The thing is: I want to limit the characters that can be typed, so I'm trying to clear the Entry widget when I reach the specific number of characters (2 in this case), but it looks like I always miss the last ...
1
2008-10-15T23:35:52Z
207,018
<p>At first, after you do the deletion, the event goes on with its normal processing, i.e. the character gets inserted. You need to signal to Tkinter that the event should be ignored.</p> <p>So in your code above, add the marked line:</p> <pre><code>if len(self.__value) &gt; 2: widgetName.delete(2,4) return "...
3
2008-10-16T00:30:58Z
[ "python", "events", "widget", "tkinter" ]
Help with <key> event in python Entry widget
206,916
<p>I'm writing some code in python and I'm having trouble when trying to retrieve content of an Entry widget. The thing is: I want to limit the characters that can be typed, so I'm trying to clear the Entry widget when I reach the specific number of characters (2 in this case), but it looks like I always miss the last ...
1
2008-10-15T23:35:52Z
225,872
<p>To be a bit more specific, Tk widgets have what are called "bindtags". When an event is processed, each bindtag on the widget is considered in order to see if it has a binding. A widget by default will have as its bindtags the widget, the widget class, the root widget, and "all". Thus, bindings to the widget will oc...
1
2008-10-22T14:06:30Z
[ "python", "events", "widget", "tkinter" ]
Python: Difference between class and instance attributes
207,000
<p>Is there any meaningful distinction between:</p> <pre><code>class A(object): foo = 5 # some default value </code></pre> <p>vs.</p> <pre><code>class B(object): def __init__(self, foo=5): self.foo = foo </code></pre> <p>If you're creating a lot of instances, is there any difference in performance...
84
2008-10-16T00:23:41Z
207,128
<p>Beyond performance considerations, there is a significant <em>semantic</em> difference. In the class attribute case, there is just one object referred to. In the instance-attribute-set-at-instantiation, there can be multiple objects referred to. For instance</p> <pre><code>&gt;&gt;&gt; class A: foo = [] &gt;&gt;...
100
2008-10-16T01:26:53Z
[ "python", "attributes" ]
Python: Difference between class and instance attributes
207,000
<p>Is there any meaningful distinction between:</p> <pre><code>class A(object): foo = 5 # some default value </code></pre> <p>vs.</p> <pre><code>class B(object): def __init__(self, foo=5): self.foo = foo </code></pre> <p>If you're creating a lot of instances, is there any difference in performance...
84
2008-10-16T00:23:41Z
207,478
<p>Just an elaboration on what Alex Coventry said, another Alex (Martelli) addressed a similar question on the <code>comp.lang.python</code> newsgroup years back. He examines the semantic difference of what a person intended vs. what he got (by using instance variables).</p> <p><a href="http://groups.google.com/group...
1
2008-10-16T04:52:22Z
[ "python", "attributes" ]
Python: Difference between class and instance attributes
207,000
<p>Is there any meaningful distinction between:</p> <pre><code>class A(object): foo = 5 # some default value </code></pre> <p>vs.</p> <pre><code>class B(object): def __init__(self, foo=5): self.foo = foo </code></pre> <p>If you're creating a lot of instances, is there any difference in performance...
84
2008-10-16T00:23:41Z
207,759
<p>The difference is that the attribute on the class is shared by all instances. The attribute on an instance is unique to that instance.</p> <p>If coming from C++, attributes on the class are more like static member variables.</p>
22
2008-10-16T08:16:28Z
[ "python", "attributes" ]
Python: Difference between class and instance attributes
207,000
<p>Is there any meaningful distinction between:</p> <pre><code>class A(object): foo = 5 # some default value </code></pre> <p>vs.</p> <pre><code>class B(object): def __init__(self, foo=5): self.foo = foo </code></pre> <p>If you're creating a lot of instances, is there any difference in performance...
84
2008-10-16T00:23:41Z
26,642,476
<p>Since people in the comments here and in two other questions marked as dups all appear to be confused about this in the same way, I think it's worth adding an additional answer on top of <a href="http://stackoverflow.com/a/207128/908494">Alex Coventry's</a>.</p> <p>The fact that Alex is assigning a value of a mutab...
11
2014-10-29T23:32:51Z
[ "python", "attributes" ]
Python: Difference between class and instance attributes
207,000
<p>Is there any meaningful distinction between:</p> <pre><code>class A(object): foo = 5 # some default value </code></pre> <p>vs.</p> <pre><code>class B(object): def __init__(self, foo=5): self.foo = foo </code></pre> <p>If you're creating a lot of instances, is there any difference in performance...
84
2008-10-16T00:23:41Z
34,126,204
<p>Here is a very good <a href="http://www.toptal.com/python/python-class-attributes-an-overly-thorough-guide" rel="nofollow">post</a>, and summary it as below.</p> <pre><code>class Bar(object): ## No need for dot syntax class_var = 1 def __init__(self, i_var): self.i_var = i_var ## Need dot synt...
4
2015-12-07T03:59:08Z
[ "python", "attributes" ]
Hooking up GUI interface with asynchronous (s)ftp operation
207,230
<p>Trying to implement a progress dialog window for file uploads that look like a cross between <a href="http://www.codinghorror.com/blog/images/ie6-download-ui.png" rel="nofollow">IE download dialog</a> and <a href="http://www.codinghorror.com/blog/images/firefox2-download-ui.png" rel="nofollow">Firefox download dialo...
1
2008-10-16T02:30:34Z
207,365
<p>"ftplib" is the standard ftp library built in to Python. In Python 2.6, it had a callback parameter added to the method used for uploading.</p> <p>That callback is a function you provide to the library; it is called once for every block that is completed.</p> <p>Your function can send a message to the GUI (perhaps...
1
2008-10-16T03:42:07Z
[ "python", "windows", "user-interface", "ftp", "sftp" ]
Hooking up GUI interface with asynchronous (s)ftp operation
207,230
<p>Trying to implement a progress dialog window for file uploads that look like a cross between <a href="http://www.codinghorror.com/blog/images/ie6-download-ui.png" rel="nofollow">IE download dialog</a> and <a href="http://www.codinghorror.com/blog/images/firefox2-download-ui.png" rel="nofollow">Firefox download dialo...
1
2008-10-16T02:30:34Z
207,794
<p>If you want a complete example of how to use threads and events to update your GUI with long running tasks using WxPython have a look at this <a href="http://wiki.wxpython.org/LongRunningTasks" rel="nofollow">page</a>. This tutorial is quite useful and helped me perform a similar program than yours.</p>
1
2008-10-16T08:38:06Z
[ "python", "windows", "user-interface", "ftp", "sftp" ]
Hooking up GUI interface with asynchronous (s)ftp operation
207,230
<p>Trying to implement a progress dialog window for file uploads that look like a cross between <a href="http://www.codinghorror.com/blog/images/ie6-download-ui.png" rel="nofollow">IE download dialog</a> and <a href="http://www.codinghorror.com/blog/images/firefox2-download-ui.png" rel="nofollow">Firefox download dialo...
1
2008-10-16T02:30:34Z
207,934
<p>If you data transfer runs in a separate thread from the GUI, you can use wx.CallAfter() whenever you have to update you progress bar from the data transfer thread. </p> <p>First, using CallAfter() is mandatory as wxPython function cannot be called from child threads.</p> <p>Second, this will decouple the execution...
1
2008-10-16T09:31:54Z
[ "python", "windows", "user-interface", "ftp", "sftp" ]
Hooking up GUI interface with asynchronous (s)ftp operation
207,230
<p>Trying to implement a progress dialog window for file uploads that look like a cross between <a href="http://www.codinghorror.com/blog/images/ie6-download-ui.png" rel="nofollow">IE download dialog</a> and <a href="http://www.codinghorror.com/blog/images/firefox2-download-ui.png" rel="nofollow">Firefox download dialo...
1
2008-10-16T02:30:34Z
216,467
<p>If you can't use Python 2.6's ftplib, there is a company offering a <em>commercial</em> solution.</p> <p>Chilkat's <a href="http://www.chilkatsoft.com/refdoc/pythonCkFtp2Ref.html" rel="nofollow" title="CKFTP2 Manual">CKFTP2</a> costs several hundreds of dollars, but promises to work with Python 2.5, and offers a fu...
0
2008-10-19T14:14:17Z
[ "python", "windows", "user-interface", "ftp", "sftp" ]
List of IP addresses/hostnames from local network in Python
207,234
<p>How can I get a list of the IP addresses or host names from a local network easily in Python?</p> <p>It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow.</p> <p><strong>Edit:</strong> By local I mean all <strong>active</strong> addresses within a local network, suc...
23
2008-10-16T02:32:33Z
207,242
<p>One of the answers in <a href="http://stackoverflow.com/questions/166506/finding-local-ip-addresses-in-python">this question</a> might help you. There seems to be a platform agnostic version for python, but I haven't tried it yet.</p>
0
2008-10-16T02:36:34Z
[ "python", "networking" ]
List of IP addresses/hostnames from local network in Python
207,234
<p>How can I get a list of the IP addresses or host names from a local network easily in Python?</p> <p>It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow.</p> <p><strong>Edit:</strong> By local I mean all <strong>active</strong> addresses within a local network, suc...
23
2008-10-16T02:32:33Z
207,246
<p>If by "local" you mean on the same network segment, then you have to perform the following steps:</p> <ol> <li>Determine your own IP address</li> <li>Determine your own netmask</li> <li>Determine the network range</li> <li>Scan all the addresses (except the lowest, which is your network address and the highest, whi...
12
2008-10-16T02:38:02Z
[ "python", "networking" ]
List of IP addresses/hostnames from local network in Python
207,234
<p>How can I get a list of the IP addresses or host names from a local network easily in Python?</p> <p>It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow.</p> <p><strong>Edit:</strong> By local I mean all <strong>active</strong> addresses within a local network, suc...
23
2008-10-16T02:32:33Z
207,775
<p>If you know the names of your computers you can use:</p> <pre><code>import socket IP1 = socket.gethostbyname(socket.gethostname()) # local IP adress of your computer IP2 = socket.gethostbyname('name_of_your_computer') # IP adress of remote computer </code></pre> <p>Otherwise you will have to scan for all the IP ad...
5
2008-10-16T08:27:41Z
[ "python", "networking" ]
List of IP addresses/hostnames from local network in Python
207,234
<p>How can I get a list of the IP addresses or host names from a local network easily in Python?</p> <p>It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow.</p> <p><strong>Edit:</strong> By local I mean all <strong>active</strong> addresses within a local network, suc...
23
2008-10-16T02:32:33Z
602,965
<p><strong>Update</strong>: The script is now located on <a href="http://github.com/bwaldvogel/neighbourhood">github</a>.</p> <p>I wrote a <a href="https://github.com/bwaldvogel/neighbourhood/blob/master/neighbourhood.py">small python script</a>, that leverages <a href="http://www.secdev.org/projects/scapy/">scapy</a>...
14
2009-03-02T16:27:29Z
[ "python", "networking" ]
List of IP addresses/hostnames from local network in Python
207,234
<p>How can I get a list of the IP addresses or host names from a local network easily in Python?</p> <p>It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow.</p> <p><strong>Edit:</strong> By local I mean all <strong>active</strong> addresses within a local network, suc...
23
2008-10-16T02:32:33Z
12,027,431
<p>Try:</p> <pre><code>import socket print [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1] </code></pre>
1
2012-08-19T14:52:13Z
[ "python", "networking" ]
List of IP addresses/hostnames from local network in Python
207,234
<p>How can I get a list of the IP addresses or host names from a local network easily in Python?</p> <p>It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow.</p> <p><strong>Edit:</strong> By local I mean all <strong>active</strong> addresses within a local network, suc...
23
2008-10-16T02:32:33Z
36,821,146
<p>Here is a small tool <strong>scanip</strong> that will help you to get all ip addresses and their corresponding mac addresses in the network (Works on Linux). This is the link for <strong>scanip</strong> (Ip and Mac scanner) written in python. <a href="https://pypi.python.org/pypi/scanip/1.0" rel="nofollow">https://...
-1
2016-04-24T09:03:01Z
[ "python", "networking" ]
extracting a parenthesized Python expression from a string
207,290
<p>I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form <code>${</code><em>expr</em><code>}</code>, for example, where <em>expr</em> is meant to be a Python expression or something resembling one. Given such a thing, one could easily imagi...
1
2008-10-16T03:02:27Z
207,310
<p>I think your best bet is to match for all curly braced entries, and then check against Python itself whether or not it's valid Python, for which <a href="http://www.python.org/doc/2.5.2/lib/compiler.html" rel="nofollow">compiler</a> would be helpful.</p>
1
2008-10-16T03:09:11Z
[ "python", "parsing" ]
extracting a parenthesized Python expression from a string
207,290
<p>I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form <code>${</code><em>expr</em><code>}</code>, for example, where <em>expr</em> is meant to be a Python expression or something resembling one. Given such a thing, one could easily imagi...
1
2008-10-16T03:02:27Z
207,502
<p>I think what you're asking about is being able to insert Python code into text files to be evaluated. There are several modules that already exist to provide this kind of functionality. You can check the Python.org <a href="http://wiki.python.org/moin/Templating" rel="nofollow"><strong>Templating wiki page</strong><...
2
2008-10-16T05:10:29Z
[ "python", "parsing" ]
extracting a parenthesized Python expression from a string
207,290
<p>I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form <code>${</code><em>expr</em><code>}</code>, for example, where <em>expr</em> is meant to be a Python expression or something resembling one. Given such a thing, one could easily imagi...
1
2008-10-16T03:02:27Z
209,420
<p>If you want to handle arbitrary expressions like <code>{'{spam': 42}["spam}"]</code>, you can't get away without full-blown parser.</p>
1
2008-10-16T16:56:42Z
[ "python", "parsing" ]
extracting a parenthesized Python expression from a string
207,290
<p>I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form <code>${</code><em>expr</em><code>}</code>, for example, where <em>expr</em> is meant to be a Python expression or something resembling one. Given such a thing, one could easily imagi...
1
2008-10-16T03:02:27Z
210,716
<p>After posting this, reading the replies so far (thanks everyone!), and thinking about the problem for a while, here is the best approach I've been able to come up with:</p> <ol> <li>Find the first <code>${</code>.</li> <li>Find the next <code>}</code> after that.</li> <li>Feed whatever's in between to <code>compile...
0
2008-10-17T00:09:51Z
[ "python", "parsing" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
207,772
<p>Can get <strong>PyDev.</strong> from <a href="http://pydev.sourceforge.net" rel="nofollow">http://pydev.sourceforge.net</a>. Its a plugin for Eclipse and is more than handy. Not to mention benefits of the old and trusted Eclipse.</p>
1
2008-10-16T08:27:02Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
207,788
<p>Komodo 5 beta 1 was released in October 2008 and has initial support for Python 3 but I don't think I'd be using it for production code yet.</p> <p>Given that Python 3 is still a very early release candidate, you may have some trouble finding mature support in IDEs.</p>
5
2008-10-16T08:34:56Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
209,303
<p>Python 3 is just <strong>not that different</strong> from Python 2.x. In terms of syntax <em>per se</em>, things that will actually need to be handled differently by the parser, the only major change is in the replacement of the <code>print</code> statement with the <code>print</code> function.</p> <p>Most of the ...
5
2008-10-16T16:23:17Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
209,844
<p>Emacs + python.el continues to be better than anything else I've tried.</p>
1
2008-10-16T19:06:20Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
800,310
<p>I can say that at the time of posting this (Apr. 28 2009, version 0.8.4h) that <a href="http://pythonide.blogspot.com/" rel="nofollow" title="SPE">SPE</a> does <em>not</em> correctly handle some python3 syntax - specifically exception handling. For example, the follow code is flagged as an error (and irritatingly, i...
0
2009-04-28T23:47:33Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
1,115,150
<p><a href="http://code.google.com/p/pyscripter/" rel="nofollow">Pyscripter</a> is the PERFECT Python IDE on windows; it's compatible even with the newly released Python 3.1.</p>
1
2009-07-12T02:03:37Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
1,115,734
<p><a href="http://pydev.org" rel="nofollow">PyDev</a> for Eclipse does support 3.0. You can configure multiple interpreters in the plug-in settings.</p> <p>In the project properties you can set:</p> <ul> <li>Project type (Python, Jython, IronPython)</li> <li>Grammar version (2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 3.0).</li> ...
3
2009-07-12T10:23:46Z
[ "python", "syntax", "ide", "python-3.x" ]
Are there any IDE's that support Python 3 syntax?
207,763
<p>I recently saw an announcement and <a href="http://www.linux.com/feature/150399" rel="nofollow">article</a> outlining the release of the first <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python 3.0</a> release candidate. I was wondering whether there were any commercial, free, open source e...
6
2008-10-16T08:21:22Z
3,525,886
<p>Geany works with python 3 if you install it and then:</p> <blockquote> <p>sudo gedit /usr/share/geany/filetypes.python</p> </blockquote> <p>change the last 2 lines with:</p> <p>compiler=python3 -c "import py_compile; py_compile.compile('%f')"</p> <p>run_cmd=python3 "%f"</p>
1
2010-08-19T20:21:26Z
[ "python", "syntax", "ide", "python-3.x" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
207,943
<p>I haven't tried it myself (yes, I just used Google and followed some links), but <a href="http://www.lag.net/paramiko/" rel="nofollow">http://www.lag.net/paramiko/</a> seems to be the recommended solution. From a cursory glance, it's an SSH implementation in pure Python, which allows tunneling for things like FTP.</...
1
2008-10-16T09:36:43Z
[ "python", "ftps" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
208,030
<p><a href="http://twistedmatrix.com/trac/wiki/TwistedProject" rel="nofollow">Twisted</a> seems to have some implementation of FTPS (FTP over SSL) under the <em>conch</em> sub-project. I am no twisted expert, but <a href="http://stackoverflow.com/users/13564/glyph">Glyph</a>, the <em>twisted</em> man himself, is listed...
3
2008-10-16T10:19:31Z
[ "python", "ftps" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
208,256
<p>I believe you could use Twisted to implement FTPS by simply using its FTP implementation, but changing the <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/protocols/ftp.py?rev=24609#L2186"><code>FTPClient.connectFactory</code></a> attribute to be a function that does something with <a href="http://twist...
9
2008-10-16T12:00:12Z
[ "python", "ftps" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
210,942
<p>I couldn't find a free sftp client for windows so I ended up wrapping Putty's PSFTP using python's subprocess module. I probably would have used the twisted implementation mentioned by Glyph if i'd known about it.</p> <p>Anyway if your interested it's available at:</p> <p><a href="http://code.google.com/p/psftplib...
1
2008-10-17T02:38:30Z
[ "python", "ftps" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
215,529
<p><a href="http://chandlerproject.org/bin/view/Projects/MeTooCrypto" rel="nofollow">M2Cypto</a> has a FTPS module. From the <a href="http://eikkitoivonen.net/m2crypto/api/M2Crypto.ftpslib-module.html" rel="nofollow">documentation</a>:</p> <pre><code>&gt;&gt;&gt; from M2Crypto import ftpslib &gt;&gt;&gt; f = ftpslib....
4
2008-10-18T20:16:09Z
[ "python", "ftps" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
2,488,262
<p>As for the server implementation you can take a look at pyftpdlib: <a href="http://code.google.com/p/pyftpdlib/" rel="nofollow">http://code.google.com/p/pyftpdlib/</a> It includes a demo script implementing a working FTPS server: <a href="http://code.google.com/p/pyftpdlib/source/browse/trunk/demo/tls_ftpd.py" rel="...
2
2010-03-21T18:47:59Z
[ "python", "ftps" ]
Python module that implements ftps
207,939
<p>I was wondering if anybody could point me towards a free ftps module for python.</p> <p>I am a complete newbie to python, but this is something I need for a work project. I need an ftps client to connect to a 3rd party ftps server.</p> <p>thanks,</p> <p>David.</p>
9
2008-10-16T09:33:39Z
4,534,996
<p>The ftplib module in Python version 2.7.1 has all of the functionality you will need, including TLS support.</p> <p><a href="http://docs.python.org/library/ftplib.html#module-ftplib">http://docs.python.org/library/ftplib.html#module-ftplib</a></p>
6
2010-12-26T18:54:21Z
[ "python", "ftps" ]
How to enable MySQL client auto re-connect with MySQLdb?
207,981
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
30
2008-10-16T09:56:05Z
210,096
<p>If you are using ubuntu Linux there was a patch added to the python-mysql package that added the ability to set that same MYSQL_OPT_RECONNECT option (see <a href="https://launchpad.net/ubuntu/hardy/+source/python-mysqldb/1.2.2-5">here</a>). I have not tried it though.</p> <p>Unfortunately, the patch was later remo...
7
2008-10-16T20:11:18Z
[ "python", "mysql" ]
How to enable MySQL client auto re-connect with MySQLdb?
207,981
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
30
2008-10-16T09:56:05Z
210,112
<p>You other bet it to work around dropped connections yourself with code.</p> <p>One way to do it would be the following:</p> <pre><code>import MySQLdb class DB: conn = None def connect(self): self.conn = MySQLdb.connect() def cursor(self): try: return self.conn.cursor() ...
-2
2008-10-16T20:15:17Z
[ "python", "mysql" ]
How to enable MySQL client auto re-connect with MySQLdb?
207,981
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
30
2008-10-16T09:56:05Z
210,885
<p>I had a similar problem with MySQL and Python, and the solution that worked for me was to upgrade MySQL to 5.0.27 (on Fedora Core 6; your system may work fine with a different version).</p> <p>I tried a lot of other things, including patching the Python libraries, but upgrading the database was a lot easier and (I ...
1
2008-10-17T01:50:49Z
[ "python", "mysql" ]
How to enable MySQL client auto re-connect with MySQLdb?
207,981
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
30
2008-10-16T09:56:05Z
982,873
<p>I solved this problem by creating a function that wraps the <code>cursor.execute()</code> method since that's what was throwing the <code>MySQLdb.OperationalError</code> exception. The other example above implies that it is the <code>conn.cursor()</code> method that throws this exception.</p> <pre><code>import MySQ...
58
2009-06-11T18:38:11Z
[ "python", "mysql" ]
How to enable MySQL client auto re-connect with MySQLdb?
207,981
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
30
2008-10-16T09:56:05Z
4,101,812
<p>you can separate the commit and the close for the connection...that's not cute but it does it.</p> <pre><code>class SqlManager(object): """ Class that handle the database operation """ def __init__(self,server, database, username, pswd): self.server = server self.dataBase = database self.user...
3
2010-11-04T22:01:44Z
[ "python", "mysql" ]
How to enable MySQL client auto re-connect with MySQLdb?
207,981
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
30
2008-10-16T09:56:05Z
29,331,237
<p>I had problems with the proposed solution because it didn't catch the exception. I am not sure why.</p> <p>I have solved the problem with the <code>ping(True)</code> statement which I think is neater:</p> <pre><code>import MySQLdb con=MySQLdb.Connect() con.ping(True) cur=con.cursor() </code></pre> <p>Got it from ...
9
2015-03-29T15:48:28Z
[ "python", "mysql" ]
How to make Apache/mod_python process collect its zombies?
208,085
<pre><code>Apache/2.2.6 (Unix) DAV/2 mod_python/3.2.8 Python/2.4.4 configured ... </code></pre> <p>One of apache processes spawns some long-running python script asynchronously, and apparently doesn't seem to collect its child process table entry. After that long-run-in-subprocess python script finishes - defunct pyth...
2
2008-10-16T10:52:00Z
209,051
<p>File a bug report.</p> <p>EDIT: I'm serious. Leaving zombies behind is a bug, and there is almost certainly nothing you can do from within Python.</p> <p>Upgrade to the latest versions, look for bug reports, post on the mailing list, switch to another product.</p>
2
2008-10-16T15:31:54Z
[ "python", "apache", "apache2", "mod-python" ]
How to make Apache/mod_python process collect its zombies?
208,085
<pre><code>Apache/2.2.6 (Unix) DAV/2 mod_python/3.2.8 Python/2.4.4 configured ... </code></pre> <p>One of apache processes spawns some long-running python script asynchronously, and apparently doesn't seem to collect its child process table entry. After that long-run-in-subprocess python script finishes - defunct pyth...
2
2008-10-16T10:52:00Z
219,073
<p>Drop mod_python in favor of <a href="http://code.google.com/p/modwsgi/" rel="nofollow">mod_wsgi</a> (is used for <a href="http://wsgi.org/wsgi/" rel="nofollow">wsgi</a>), which does not leave orphaned zombies around afaik.</p>
2
2008-10-20T16:31:46Z
[ "python", "apache", "apache2", "mod-python" ]
How to read and write multiple files?
208,120
<p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads ...
4
2008-10-16T11:06:36Z
208,156
<pre><code>import sys # argv is your commandline arguments, argv[0] is your program name, so skip it for n in sys.argv[1:]: print(n) #print out the filename we are currently processing input = open(n, "r") output = open(n + ".out", "w") # do some processing input.close() output.close() </code><...
9
2008-10-16T11:23:29Z
[ "python" ]
How to read and write multiple files?
208,120
<p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads ...
4
2008-10-16T11:06:36Z
208,227
<p>You may find the <a href="https://docs.python.org/2/library/fileinput.html" rel="nofollow"><code>fileinput</code></a> module useful. It is designed for exactly this problem.</p>
5
2008-10-16T11:51:04Z
[ "python" ]
How to read and write multiple files?
208,120
<p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads ...
4
2008-10-16T11:06:36Z
208,342
<p>I think what you miss is how to retrieve all the files in that directory. To do so, use the glob module. Here is an example which will duplicate all the files with extension *.txt to files with extension *.out</p> <pre><code>import glob list_of_files = glob.glob('./*.txt') # create the list of file for f...
4
2008-10-16T12:28:48Z
[ "python" ]
How to read and write multiple files?
208,120
<p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads ...
4
2008-10-16T11:06:36Z
208,731
<p>Combined answer incorporating directory or specific list of filenames arguments:</p> <pre><code>import sys import os.path import glob def processFile(filename): fileHandle = open(filename, "r") for line in fileHandle: # do some processing pass fileHandle.close() def outputResults(filen...
0
2008-10-16T14:12:40Z
[ "python" ]
How to read and write multiple files?
208,120
<p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads ...
4
2008-10-16T11:06:36Z
211,188
<p>I've just learned of the os.walk() command recently, and it may help you here. It allows you to walk down a directory tree structure.</p> <pre><code>import os OUTPUT_DIR = 'C:\\RESULTS' for path, dirs, files in os.walk('.'): for file in files: read_f = open(os.join(path,file),'r') write_f = open...
1
2008-10-17T05:53:51Z
[ "python" ]
How to read and write multiple files?
208,120
<p>I want to write a program for this: In a folder I have <em>n</em> number of files; first read one file and perform some operation then store result in a separate file. Then read 2nd file, perform operation again and save result in new 2nd file. Do the same procedure for <em>n</em> number of files. The program reads ...
4
2008-10-16T11:06:36Z
11,945,810
<pre><code>from pylab import * import csv import os import glob import re x=[] y=[] f=open("one.txt",'w') for infile in glob.glob(('*.csv')): # print "" +infile csv23=csv2rec(""+infile,'rb',delimiter=',') for line in csv23: x.append(line[1]) # print len(x) for i in range...
0
2012-08-14T04:30:15Z
[ "python" ]
How to base64 encode a PDF file in Python
208,894
<p>How should I base64 encode a PDF file for transport over XML-RPC in Python?</p>
6
2008-10-16T14:54:49Z
208,950
<p>You can do it with the <a href="http://www.python.org/doc/2.5.2/lib/module-base64.html" rel="nofollow">base64 library</a>, legacy interface.</p>
1
2008-10-16T15:08:49Z
[ "python", "encoding", "base64", "xml-rpc" ]
How to base64 encode a PDF file in Python
208,894
<p>How should I base64 encode a PDF file for transport over XML-RPC in Python?</p>
6
2008-10-16T14:54:49Z
208,960
<p>Actually, after some more digging, it looks like the <code>xmlrpclib module may have the piece I need with it's <code>Binary</code> helper class:</p> <pre> binary_obj = xmlrpclib.Binary( open('foo.pdf').read() ) </code></pre> <p>Here's an example from the <a href="http://trac-hacks.org/wiki/XmlRpcPlugin" rel="nofo...
4
2008-10-16T15:09:33Z
[ "python", "encoding", "base64", "xml-rpc" ]
How to base64 encode a PDF file in Python
208,894
<p>How should I base64 encode a PDF file for transport over XML-RPC in Python?</p>
6
2008-10-16T14:54:49Z
208,975
<p>Looks like you might be able to use the <a href="http://docs.python.org/library/binascii.html" rel="nofollow">binascii</a> module</p> <blockquote> <p>binascii.b2a_base64(data)</p> <p>Convert binary data to a line of ASCII characters in base64 coding. The return value is the converted line, including a newlin...
0
2008-10-16T15:13:02Z
[ "python", "encoding", "base64", "xml-rpc" ]
How to base64 encode a PDF file in Python
208,894
<p>How should I base64 encode a PDF file for transport over XML-RPC in Python?</p>
6
2008-10-16T14:54:49Z
209,363
<p><i>NOTE: this is a community-wiki owned copy of Pat Notz's answer. This answer can be selected as the chosen answer. Edit freely to improve.</i></p> <h3>Pat Notz says:</h3> <p>Actually, after some more digging, it looks like the <code>xmlrpclib</code> module may have the piece I need with its <code>Binary</code> h...
1
2008-10-16T16:38:08Z
[ "python", "encoding", "base64", "xml-rpc" ]
How to base64 encode a PDF file in Python
208,894
<p>How should I base64 encode a PDF file for transport over XML-RPC in Python?</p>
6
2008-10-16T14:54:49Z
210,534
<p>If you don't want to use the xmlrpclib's Binary class, you can just use the .encode() method of strings:</p> <pre><code>a = open("pdf_reference.pdf", "rb").read().encode("base64") </code></pre>
21
2008-10-16T22:33:24Z
[ "python", "encoding", "base64", "xml-rpc" ]
Django template with jquery: Ajax update on existing page
209,023
<p>I have a Google App Engine that has a form. When the user clicks on the submit button, AJAX operation will be called, and the server will output something to append to the end of the very page where it comes from. How, I have a Django template, and I intend to use jquery. I have the following view:</p> <pre><code>...
3
2008-10-16T15:27:38Z
266,862
<p>Without being able to test the code, what are your results? Have you checked the results returned by the AJAX call? I would suggest you run Firefox with Firebug and log the AJAX results to the Firebug console to see what you get:</p> <pre><code>//... success: function( result ) { console.log( resul...
2
2008-11-05T21:53:18Z
[ "jquery", "python", "django", "google-app-engine", "django-templates" ]
Django template with jquery: Ajax update on existing page
209,023
<p>I have a Google App Engine that has a form. When the user clicks on the submit button, AJAX operation will be called, and the server will output something to append to the end of the very page where it comes from. How, I have a Django template, and I intend to use jquery. I have the following view:</p> <pre><code>...
3
2008-10-16T15:27:38Z
832,625
<p>here is an example of my success function </p> <pre><code>success: function(json){ $('#gallons_cont').html(json['gallons']); $('#area_cont').html(json['area']); $('#usage_cont').html(json['usage']) $('#results_json').show('slow'); ...
1
2009-05-07T02:26:37Z
[ "jquery", "python", "django", "google-app-engine", "django-templates" ]
Why do I receive an ImportError when running one of the CherryPy tutorials
209,429
<p>I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:</p> <pre><code>$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/ $ python tut09_files.py Traceback (most recent call last): File "tut09_files.py", line 48, in &lt;module&gt; from cherrypy.lib import static ImportError...
1
2008-10-16T16:58:43Z
209,488
<p>This works for me, and I'm also using CherryPy 3.1.0, so I'm not sure what to tell you.</p> <p>Look in your /Library/Python/2.5/site-packages/cherrypy/lib directory for a file named static.py; if this file exists then I'm not sure what to tell you. If it doesn't then something has happened to your CherryPy and I'd...
1
2008-10-16T17:16:56Z
[ "python", "cherrypy" ]
Why do I receive an ImportError when running one of the CherryPy tutorials
209,429
<p>I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:</p> <pre><code>$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/ $ python tut09_files.py Traceback (most recent call last): File "tut09_files.py", line 48, in &lt;module&gt; from cherrypy.lib import static ImportError...
1
2008-10-16T16:58:43Z
216,440
<p>I had an old CherryPy-2.3.0-py2.5.egg file in my site-packages. After removing the old .egg I could run the tutorial.</p>
1
2008-10-19T13:43:18Z
[ "python", "cherrypy" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
209,474
<p>Python would be perfectly fine for text file manipulation. For learning, check <a href="http://stackoverflow.com/questions/918/how-to-learn-python-good-example-code#964">here</a>.</p>
0
2008-10-16T17:13:39Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
209,557
<p>I suggest the awesome online book <em><a href="http://www.diveintopython.net">Dive Into Python</a></em>. It's how I learned the language originally.</p> <p>Beyone teaching you the basic structure of the language, and a whole lot of useful data structures, it has a good chapter on <a href="http://www.diveintopython...
8
2008-10-16T17:40:43Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
209,562
<p>Any shell has several sets of features.</p> <ul> <li><p>The Essential Linux/Unix commands. All of these are available through the <a href="https://docs.python.org/3/library/subprocess.html">subprocess</a> library. This isn't always the best first choice for doing <em>all</em> external commands. Look also at <a h...
127
2008-10-16T17:41:44Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
209,565
<p>If your textfile manipulation usually is one-time, possibly done on the shell-prompt, you will not get anything better from python.</p> <p>On the other hand, if you usually have to do the same (or similar) task over and over, and you have to write your scripts for doing that, then python is great - and you can easi...
1
2008-10-16T17:42:48Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
209,665
<p>Your best bet is a tool that is specifically geared towards your problem. If it's processing text files, then Sed, Awk and Perl are the top contenders. Python is a general-purpose <em>dynamic</em> language. As with any general purpose language, there's support for file-manipulation, but that isn't what it's core ...
2
2008-10-16T18:14:48Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
209,670
<ul> <li>If you want to use Python as a shell, why not have a look at <a href="http://ipython.org/">IPython</a> ? It is also good to learn interactively the language.</li> <li>If you do a lot of text manipulation, and if you use Vim as a text editor, you can also directly write plugins for Vim in python. just type ":he...
28
2008-10-16T18:16:52Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
210,290
<p>In the beginning there was sh, sed, and awk (and find, and grep, and...). It was good. But awk can be an odd little beast and hard to remember if you don't use it often. Then the great camel created Perl. Perl was a system administrator's dream. It was like shell scripting on steroids. Text processing, including reg...
16
2008-10-16T20:58:33Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
210,429
<p>I have built semi-long shell scripts (300-500 lines) and Python code which does similar functionality. When many external commands are being executed, I find the shell is easier to use. Perl is also a good option when there is lots of text manipulation.</p>
4
2008-10-16T21:49:19Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
210,474
<p>Adding to previous answers: check the <a href="http://www.noah.org/wiki/Pexpect">pexpect</a> module for dealing with interactive commands (adduser, passwd etc.)</p>
6
2008-10-16T22:05:19Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
3,851,454
<p>While researching this topic, I found <a href="http://hg.mozilla.org/users/tmielczarek_mozilla.com/pyshell/file/tip/shell.py" rel="nofollow">this proof-of-concept code</a> (via a comment at <a href="http://jlebar.com/2010/2/1/Replacing_Bash.html" rel="nofollow">http://jlebar.com/2010/2/1/Replacing_Bash.html</a>) tha...
2
2010-10-03T20:21:33Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
12,915,952
<p>Yes, of course :)</p> <p>Take a look at these libraries which help you <strong><em>Never write shell scripts again</em></strong> (Plumbum's motto).</p> <ul> <li><a href="http://plumbum.readthedocs.org/en/latest/">Plumbum</a> </li> <li><a href="https://bitbucket.org/vinay.sajip/sarge/">Sarge</a></li> <li><a href="h...
81
2012-10-16T13:37:46Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
15,712,610
<p>I just discovered how to combine the best parts of bash and ipython. Up to now this seems more comfortable to me than using subprocess and so on. You can easily copy big parts of existing bash scripts and e.g. add error handling in the python way :) And here is my result:</p> <pre><code>#!/usr/bin/env ipython3 # *...
42
2013-03-29T22:49:18Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
16,726,383
<p>One reason I love Python is that it is much better standardized than the POSIX tools. I have to double and triple check that each bit is compatible with other operating systems. A program written on a Linux system might not work the same on a BSD system of OSX. With Python, I just have to check that the target sy...
7
2013-05-24T01:23:24Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
20,313,297
<p>I will give here my opinion based on experience:</p> <p>For shell:</p> <ul> <li>shell can very easily spawn read-only code. Write it and when you come back to it, you will never figure out what you did again. It's very easy to accomplish this.</li> <li>shell can do A LOT of text processing, splitting, etc in one l...
4
2013-12-01T14:40:14Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
25,820,270
<p><a href="http://github.com/russell91/pythonpy" rel="nofollow">pythonpy</a> is a tool that provides easy access to many of the features from awk and sed, but using python syntax:</p> <pre><code>$ echo me2 | py -x 're.sub("me", "you", x)' you2 </code></pre>
2
2014-09-13T05:55:20Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
27,881,288
<p>I have published a package on PyPI: <a href="https://pypi.python.org/pypi/ez" rel="nofollow">ez</a>.<br> Use <code>pip install ez</code> to install it.</p> <p>It has packed common commands in shell and nicely my lib uses basically the same syntax as shell. e.g., cp(source, destination) can handle both file and fol...
0
2015-01-10T21:14:27Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
30,617,053
<p>As of 2015 and Python 3.4's release, there's now a reasonably complete user-interactive shell available at: <a href="http://xon.sh/">http://xon.sh/</a> or <a href="https://github.com/scopatz/xonsh/">https://github.com/scopatz/xonsh</a></p> <p>The <a href="http://xon.sh/_static/xonsh-demo.webm">demonstration video</...
33
2015-06-03T10:08:43Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
35,443,255
<p>You can use python instead of bash with the <a href="https://github.com/lamerman/shellpy" rel="nofollow">ShellPy</a> library. </p> <p>Here is an example that downloads avatar of Python user from Github:</p> <pre class="lang-python prettyprint-override"><code>import json import os import tempfile # get the api ans...
1
2016-02-16T21:23:04Z
[ "python", "bash", "shell" ]
Can I use Python as a Bash replacement?
209,470
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p> <p>I've seen mentioned a few places that python is good for this kind of thing, I know a little and I would like to know more. Is Python a good choice for this, and is there a good book or guide to...
207
2008-10-16T17:11:37Z
35,890,675
<p>I wish there was something decent to replace bash scripting but really there isn't.</p> <p>Python would seem like a great candidate until you're hit with the awkward standard library functions for file manipulation and spawning processes (os.popen3) and communicating with them.</p>
0
2016-03-09T11:43:18Z
[ "python", "bash", "shell" ]
Howto do python command-line autocompletion but NOT only at the beginning of a string
209,484
<p>Python, through it's readline bindings allows for great command-line autocompletion (as described in <a href="http://stackoverflow.com/questions/187621/how-to-make-a-python-command-line-program-autocomplete-arbitrary-things-not-int">here</a>).</p> <p>But, the completion only seems to work at the beginning of string...
6
2008-10-16T17:16:34Z
209,503
<p>I'm not sure I understand the problem. You could use readline.clear_history and readline.add_history to set up the completable strings you want, then control-r to search backword in the history (just as if you were at a shell prompt). For example:</p> <pre><code>#!/usr/bin/env python import readline readline.cl...
10
2008-10-16T17:23:34Z
[ "python", "linux", "unix", "command-line", "autocomplete" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
209,529
<p><code>int(hexString, 16)</code> does the trick, and works with and without the 0x prefix:</p> <pre><code>&gt;&gt;&gt; int("a", 16) 10 &gt;&gt;&gt; int("0xa",16) 10 </code></pre>
99
2008-10-16T17:32:10Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
209,530
<p>For any given string s:</p> <pre><code>int(s, 16) </code></pre>
32
2008-10-16T17:32:32Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
209,550
<p><strong>Without</strong> the 0x prefix, you need to specify the base explicitly, otherwise there's no way to tell:</p> <pre><code>x = int("deadbeef", 16) </code></pre> <p><strong>With</strong> the 0x prefix, Python can distinguish hex and decimal automatically.</p> <pre><code>&gt;&gt;&gt; print int("0xdeadbeef", ...
594
2008-10-16T17:37:52Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
5,313,035
<p>To convert a DWORD from hex to a signed integer , implement two's complement like this:</p> <pre><code>~ (0xffffffff - int('0xdeadbeef', 16)) + 1 </code></pre>
-3
2011-03-15T14:14:09Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
11,275,700
<p>Adding to Dan's answer above: if you supply the int() function with a hex string, you will have to specify the base as 16 or it will not think you gave it a valid value. Specifying base 16 is unnecessary for hex numbers not contained in strings.</p> <pre><code>print int(0xdeadbeef) # valid myHex = "0xdeadbeef" pri...
9
2012-06-30T16:25:01Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
12,049,551
<p>with '0x' prefix, you might also use eval function</p> <p>For example</p> <pre><code>&gt;&gt;a='0xff' &gt;&gt;eval(a) 255 </code></pre>
-2
2012-08-21T06:39:36Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
17,250,080
<p>The formatter option '%x' % seems to work in assignment statements as well for me. (Assuming Python 3.0 and later)</p> <p><strong>Example</strong> </p> <pre><code>a = int('0x100', 16) print(a) #256 print('%x' % a) #100 b = a print(b) #256 c = '%x' % a print(c) #100 </code></pre>
1
2013-06-22T11:10:32Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
21,187,085
<p>The worst way:</p> <pre><code>&gt;&gt;&gt; def hex_to_int(x): return eval("0x" + x) &gt;&gt;&gt; hex_to_int("c0ffee") 12648430 </code></pre> <h1><em>Please don't do this!</em></h1> <p><a href="http://stackoverflow.com/questions/1832940/is-using-eval-in-python-a-bad-practice">Is Using eval In Python A Bad Pra...
4
2014-01-17T13:20:15Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
30,270,489
<p>In Python 2.7, <code>int('deadbeef',10)</code> doesn't seem to work. </p> <p>The following works for me:</p> <pre><code>&gt;&gt;a = int('deadbeef',16) &gt;&gt;float(a) 3735928559.0 </code></pre>
2
2015-05-16T00:13:25Z
[ "python", "string", "hex" ]
Convert hex string to int in Python
209,513
<p>How do I convert a hex string to an int in Python? </p> <p>I may have it as "<code>0xffff</code>" or just "<code>ffff</code>".</p>
414
2008-10-16T17:28:03Z
37,221,971
<blockquote> <h1>Convert hex string to int in Python</h1> <p>I may have it as <code>"0xffff"</code> or just <code>"ffff"</code>.</p> </blockquote> <p>To convert a string to an int, pass the string to <code>int</code> along with the base you are converting from. </p> <p>Both strings will suffice for conversion ...
2
2016-05-14T02:50:29Z
[ "python", "string", "hex" ]
Map two lists into a dictionary in Python
209,840
<p>Imagine that you have:</p> <pre><code>keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') </code></pre> <p>What is the simplest way to produce the following dictionary ?</p> <pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'} </code></pre> <p>This code works, but I'm not really proud of i...
435
2008-10-16T19:05:47Z
209,854
<p>Like this:</p> <pre><code>&gt;&gt;&gt; keys = ['a', 'b', 'c'] &gt;&gt;&gt; values = [1, 2, 3] &gt;&gt;&gt; dictionary = dict(zip(keys, values)) &gt;&gt;&gt; print dictionary {'a': 1, 'b': 2, 'c': 3} </code></pre> <p>Voila :-) The pairwise dict constructor and zip function are awesomely useful: <a href="https://do...
770
2008-10-16T19:09:05Z
[ "python", "dictionary" ]
Map two lists into a dictionary in Python
209,840
<p>Imagine that you have:</p> <pre><code>keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') </code></pre> <p>What is the simplest way to produce the following dictionary ?</p> <pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'} </code></pre> <p>This code works, but I'm not really proud of i...
435
2008-10-16T19:05:47Z
209,855
<pre><code>&gt;&gt;&gt; keys = ('name', 'age', 'food') &gt;&gt;&gt; values = ('Monty', 42, 'spam') &gt;&gt;&gt; dict(zip(keys, values)) {'food': 'spam', 'age': 42, 'name': 'Monty'} </code></pre>
25
2008-10-16T19:09:18Z
[ "python", "dictionary" ]
Map two lists into a dictionary in Python
209,840
<p>Imagine that you have:</p> <pre><code>keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') </code></pre> <p>What is the simplest way to produce the following dictionary ?</p> <pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'} </code></pre> <p>This code works, but I'm not really proud of i...
435
2008-10-16T19:05:47Z
209,880
<p>Try this:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; keys = ('name', 'age', 'food') &gt;&gt;&gt; values = ('Monty', 42, 'spam') &gt;&gt;&gt; adict = dict(itertools.izip(keys,values)) &gt;&gt;&gt; adict {'food': 'spam', 'age': 42, 'name': 'Monty'} </code></pre> <p>It was the simplest solution I could...
92
2008-10-16T19:16:02Z
[ "python", "dictionary" ]
Map two lists into a dictionary in Python
209,840
<p>Imagine that you have:</p> <pre><code>keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') </code></pre> <p>What is the simplest way to produce the following dictionary ?</p> <pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'} </code></pre> <p>This code works, but I'm not really proud of i...
435
2008-10-16T19:05:47Z
210,234
<p>If you need to transform keys or values before creating a dictionary then a <a href="http://docs.python.org/ref/genexpr.html">generator expression</a> could be used. Example:</p> <pre><code>&gt;&gt;&gt; adict = dict((str(k), v) for k, v in zip(['a', 1, 'b'], [2, 'c', 3])) </code></pre> <p>Take a look <a href="http...
11
2008-10-16T20:45:04Z
[ "python", "dictionary" ]
Map two lists into a dictionary in Python
209,840
<p>Imagine that you have:</p> <pre><code>keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') </code></pre> <p>What is the simplest way to produce the following dictionary ?</p> <pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'} </code></pre> <p>This code works, but I'm not really proud of i...
435
2008-10-16T19:05:47Z
10,971,932
<p>You can also use dictionary comprehensions in Python ≥ 2.7:</p> <pre><code>&gt;&gt;&gt; keys = ('name', 'age', 'food') &gt;&gt;&gt; values = ('Monty', 42, 'spam') &gt;&gt;&gt; {k: v for k, v in zip(keys, values)} {'food': 'spam', 'age': 42, 'name': 'Monty'} </code></pre>
23
2012-06-10T20:03:34Z
[ "python", "dictionary" ]
Map two lists into a dictionary in Python
209,840
<p>Imagine that you have:</p> <pre><code>keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') </code></pre> <p>What is the simplest way to produce the following dictionary ?</p> <pre><code>dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'} </code></pre> <p>This code works, but I'm not really proud of i...
435
2008-10-16T19:05:47Z
15,709,950
<p>For those who need simple code and aren’t familiar with <code>zip</code>:</p> <pre><code>List1 = ['This', 'is', 'a', 'list'] List2 = ['Put', 'this', 'into', 'dictionary'] </code></pre> <p>This can be done by one line of code:</p> <pre><code>d = {List1[n]: List2[n] for n in range(len(List1))} </code></pre>
5
2013-03-29T19:13:45Z
[ "python", "dictionary" ]