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
What if setuptools isn't installed?
1,666,482
<p>I'm just learning the art of writing a <code>setup.py</code> file for my project. I see there's lots of talk about <code>setuptools</code>, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if se...
3
2009-11-03T10:27:04Z
1,666,539
<p>You can download Windows EXE installers and a Linux RPM from here</p> <p><a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">http://pypi.python.org/pypi/setuptools</a></p> <p>Then, once you have setuptools in place you can use the <code>easy_install</code> command to both download and install new packa...
0
2009-11-03T10:38:12Z
[ "python", "deployment", "setuptools", "distutils" ]
What if setuptools isn't installed?
1,666,482
<p>I'm just learning the art of writing a <code>setup.py</code> file for my project. I see there's lots of talk about <code>setuptools</code>, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if se...
3
2009-11-03T10:27:04Z
1,666,592
<p>In most librarys I ever installed for python, a warning apears "You have to install setuptools". You could do it as well I think, you could add a link so the user don't have to search the internet for it.</p>
2
2009-11-03T10:49:10Z
[ "python", "deployment", "setuptools", "distutils" ]
What if setuptools isn't installed?
1,666,482
<p>I'm just learning the art of writing a <code>setup.py</code> file for my project. I see there's lots of talk about <code>setuptools</code>, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if se...
3
2009-11-03T10:27:04Z
1,666,595
<p>The standard way to distribute packages with setuptools includes an <code>ez_setup.py</code> script which will automatically download and install setuptools itself - on Windows I believe it will actually install an executable for <code>easy_install</code>. You can get this from the standard setuptools/easy_install d...
4
2009-11-03T10:49:20Z
[ "python", "deployment", "setuptools", "distutils" ]
What if setuptools isn't installed?
1,666,482
<p>I'm just learning the art of writing a <code>setup.py</code> file for my project. I see there's lots of talk about <code>setuptools</code>, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if se...
3
2009-11-03T10:27:04Z
1,666,606
<p>I would say it depends on what kind of user you are addressing.</p> <p>If they are simply users and not Python programmers, or if they are basic programmers, using setuptools might be a little bit too much at first. For those the distutils is perfect.</p> <p>For clients, I would definitely stick to distutils.</p> ...
0
2009-11-03T10:51:20Z
[ "python", "deployment", "setuptools", "distutils" ]
What if setuptools isn't installed?
1,666,482
<p>I'm just learning the art of writing a <code>setup.py</code> file for my project. I see there's lots of talk about <code>setuptools</code>, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if se...
3
2009-11-03T10:27:04Z
1,666,911
<p>You can't assume it's installed. There are ways around that, you can fall back to distutils (but then why have setuptools in the first place) or you can install setuptools in setup.py (but I think that's evil).</p> <p>Use setuptools only if you need it.</p> <p>When it comes to setuptools vs distrubute, they are co...
1
2009-11-03T12:00:52Z
[ "python", "deployment", "setuptools", "distutils" ]
What if setuptools isn't installed?
1,666,482
<p>I'm just learning the art of writing a <code>setup.py</code> file for my project. I see there's lots of talk about <code>setuptools</code>, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if se...
3
2009-11-03T10:27:04Z
1,698,562
<p>I have used setuptools to compile many python scripts that I have written into windows EXEs. However, it has always been my understanding (from experience) that the computer running the compiled EXE does not need to have setup tools installed.</p> <p>Hope that helps</p>
2
2009-11-09T00:52:28Z
[ "python", "deployment", "setuptools", "distutils" ]
Public API with Private Elements in Python
1,666,533
<p>I'm working on a web mapping service and would like to provide my users with a Python API that they can use to create custom plugins. These plugins would be running on my server so I'm trying to lock down Python as much as possible.</p> <p>To ensure that users can't access files they are not supposed to, I'm planni...
0
2009-11-03T10:37:34Z
1,666,548
<p>This looks like a clean way to implement this to me. I believe it's also sometimes referred to as the "Facade" design pattern.</p> <p>In python this is very easy to implement using explicit method delegation (a short snippet to give you a general idea):</p> <pre><code>class FacadingAPI(): def __init__(fullapi_...
2
2009-11-03T10:40:05Z
[ "python", "security", "api", "class", "pipe" ]
Public API with Private Elements in Python
1,666,533
<p>I'm working on a web mapping service and would like to provide my users with a Python API that they can use to create custom plugins. These plugins would be running on my server so I'm trying to lock down Python as much as possible.</p> <p>To ensure that users can't access files they are not supposed to, I'm planni...
0
2009-11-03T10:37:34Z
1,666,643
<p>There are many ways that you can do this. I tend to have a tuple with all the function names that are available and then check if the function being called is in the tuple, if not then throw an error.</p> <p>e.g.</p> <pre><code>funcs = ("available","functions","here") if (calledFunction in funcs): #do something...
0
2009-11-03T11:00:31Z
[ "python", "security", "api", "class", "pipe" ]
Editing Windows registry, from Python, Under Linux
1,666,690
<p>I am looking for a Python API (or a C API as I am willing to bind) for editing Windows registries from XP to 7 from within a Linux system.</p> <p>The Windows target will be a mounted volume under Linux.</p> <p>I would be willing to code a library if none exists. Therefore, any docs or internals on the registry wou...
4
2009-11-03T11:12:24Z
1,667,128
<p>I think you are out of luck, as I couldn't find any such lib. when I need such thing some years back(to change a windows image file). Also writing it yourself isn't easy and I also couldn't find any MS document describing the format. </p> <p>here are some links which come up in google search and describe format par...
0
2009-11-03T12:46:39Z
[ "python", "windows", "linux", "registry" ]
Editing Windows registry, from Python, Under Linux
1,666,690
<p>I am looking for a Python API (or a C API as I am willing to bind) for editing Windows registries from XP to 7 from within a Linux system.</p> <p>The Windows target will be a mounted volume under Linux.</p> <p>I would be willing to code a library if none exists. Therefore, any docs or internals on the registry wou...
4
2009-11-03T11:12:24Z
1,667,132
<p>You may want to have a look at <a href="http://home.eunet.no/pnordahl/ntpasswd/" rel="nofollow">this project</a>. The initial idea was to recover passwords but all the tools are there to edit registry entries.</p> <p>It sounds like a dangerous idea though, I would rather find a way to launch a Python script - even ...
1
2009-11-03T12:47:17Z
[ "python", "windows", "linux", "registry" ]
Editing Windows registry, from Python, Under Linux
1,666,690
<p>I am looking for a Python API (or a C API as I am willing to bind) for editing Windows registries from XP to 7 from within a Linux system.</p> <p>The Windows target will be a mounted volume under Linux.</p> <p>I would be willing to code a library if none exists. Therefore, any docs or internals on the registry wou...
4
2009-11-03T11:12:24Z
1,667,151
<p>OK, so you're after a hive file editor?</p> <p>I wrote a <code>winregistry</code> module that does this (for both NT and win9x hives). It's not really ready for the public but worked quite well with the data I was using at the time. I'm not sure what state I left it in and I haven't tested it with Win7 hives, but m...
7
2009-11-03T12:50:19Z
[ "python", "windows", "linux", "registry" ]
Editing Windows registry, from Python, Under Linux
1,666,690
<p>I am looking for a Python API (or a C API as I am willing to bind) for editing Windows registries from XP to 7 from within a Linux system.</p> <p>The Windows target will be a mounted volume under Linux.</p> <p>I would be willing to code a library if none exists. Therefore, any docs or internals on the registry wou...
4
2009-11-03T11:12:24Z
5,344,868
<p>Creddump is written in Python (no C extensions) and has code to read the registry (though not write it). It may help you get started:</p> <p><a href="http://code.google.com/p/creddump/" rel="nofollow">http://code.google.com/p/creddump/</a></p>
0
2011-03-17T20:30:15Z
[ "python", "windows", "linux", "registry" ]
How to count the number of times something occurs inside a certain string?
1,666,700
<p>In python, I remember there is a function to do this.</p> <p>.count? </p> <p>"The big brown fox is brown" brown = 2.</p>
7
2009-11-03T11:16:23Z
1,666,709
<p>why not read the docs first, it's very simple:</p> <pre><code>&gt;&gt;&gt; "The big brown fox is brown".count("brown") 2 </code></pre>
23
2009-11-03T11:17:59Z
[ "python" ]
How to count the number of times something occurs inside a certain string?
1,666,700
<p>In python, I remember there is a function to do this.</p> <p>.count? </p> <p>"The big brown fox is brown" brown = 2.</p>
7
2009-11-03T11:16:23Z
1,666,756
<p>One thing worth learning if you're a Python beginner is how to use <a href="http://docs.python.org/tutorial/interpreter.html#interactive-mode">interactive mode</a> to help with this. The first thing to learn is the <a href="http://docs.python.org/library/functions.html"><code>dir</code> function</a> which will tell...
17
2009-11-03T11:29:54Z
[ "python" ]
How to delete a certain IE cookie from python?
1,666,989
<p>how can I delete IE 8 cookies for a certain site from Python?</p>
1
2009-11-03T12:18:48Z
1,667,121
<p>I've found out that under Windows seven cookies are stored in </p> <blockquote> <p>C:\Users(user)\AppData\Roaming\Microsoft\Windows\Cookies</p> </blockquote> <p>in format (user)@host[\d].txt, so I guess just deleting the corresponding file is way to go.</p>
0
2009-11-03T12:44:54Z
[ "python", "cookies", "internet-explorer" ]
How to delete a certain IE cookie from python?
1,666,989
<p>how can I delete IE 8 cookies for a certain site from Python?</p>
1
2009-11-03T12:18:48Z
1,667,334
<p>It is probably cleaner and less error prone to use the Python standard library module: <a href="http://docs.python.org/library/cookielib.html" rel="nofollow">cookielib</a> this provides functions to manipulate cookies in various ways. </p> <p>Unfortunately to use this with IE consider the third party extension to t...
1
2009-11-03T13:27:02Z
[ "python", "cookies", "internet-explorer" ]
file size is dramatically increased after pickle
1,667,144
<p>I'm reading in a file and sending the data (once encrypted) to a dictionary, with a hash of the data before and after encryption. I then pickle the dictionary but find the file size is massive compared to the source file size. If I write the encrypted data straight to a file the size is identical to the source. Any ...
3
2009-11-03T12:48:28Z
1,667,184
<p>Try using a binary pickle by specifying <code>protocol=2</code> as a keyword argument to pickle.dump. It should be much more efficient.</p>
6
2009-11-03T12:56:52Z
[ "python", "encryption", "aes", "pickle" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
1,667,268
<blockquote> <p>surely this is a nice tidy, python interface to the mount system call.</p> <p>I can't find it (I thought it would just be a nice, easy os.mount()).</p> </blockquote> <p>Surely, there is none. What would this function do on Windows?</p> <p>Use the shell command instead.</p>
1
2009-11-03T13:12:44Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
1,667,319
<p>Mounting is a pretty rare operation, so it's doubtful that there is any direct python way to do it.</p> <p>Either use <a href="http://docs.python.org/library/ctypes.html" rel="nofollow"><code>ctypes</code></a> to do the operation directly from python, or else (and probably better), use <code>subprocess</code> to ca...
2
2009-11-03T13:23:48Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
1,667,328
<p>Badly, mounting and unmounting belongs to the things that are highly system dependent and since they are</p> <ul> <li>rarely used and</li> <li>can affect system stability</li> </ul> <p>There is no solution that is portable available. Since that, I agree with Ferdinand Beyer, that it is unlikely, a general Python s...
0
2009-11-03T13:25:15Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
1,667,358
<p>Import <code>cdll</code> from <code>ctypes</code>. Then load your os <code>libc</code>, then use <code>libc.mount()</code></p> <p>Read <code>libc</code>'s docs for mount parameters</p>
6
2009-11-03T13:32:33Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
6,963,468
<p>Note that calling your libc mount function will require root privileges; Popen(['mount'...) only will if the particular mounting isn't blessed in fstab (it is the mount executable, setuid root, that performs these checks).</p>
2
2011-08-05T22:59:00Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
17,104,528
<p>As others have stated, a direct access to the syscall will not help you, unless you're running as root (which is generally bad, for many reasons). Thus, it is best to call out to the "mount" program, and hope that <code>/etc/fstab</code> has enabled mounts for users.</p> <p>The best way to invoke <strong>mount</str...
1
2013-06-14T08:44:31Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
26,084,472
<p>Another option would be to use the fairly new <a href="https://github.com/amoffat/sh" rel="nofollow">sh</a> module. According to its <a href="http://amoffat.github.io/sh/" rel="nofollow">documentation</a> it provides fluent integration with Shell commands from within Python.</p> <p>I am trying it out now and it l...
1
2014-09-28T11:36:58Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
29,156,997
<p>As others have pointed out, there is no built-in mount function. However, it is easy to create one using ctypes, and this is a bit lighter weight and more reliable than using a shell command:</p> <pre><code>import ctypes import os def mount(source, target, fs, options=''): ret = ctypes.CDLL('libc.so.6', use_err...
9
2015-03-19T23:46:12Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
33,179,540
<p>I know this is old but I had a similar issue and pexpect solved it. I could mount my Windows shared drive using the mount command but I couldn't pass my password in because it had to be escaped. I grew tired of escaping it and tried to use a credentials file which also caused issues. This seems to work for me.</p> ...
0
2015-10-16T21:05:53Z
[ "python", "unix" ]
How do I mount a filesystem using Python?
1,667,257
<p>I'm sure this is a easy question, my Google-fu is obviously failing me.</p> <p>How do I mount a filesystem using Python, the equivalent of running the shell command <code>mount ...</code>?</p> <p>Obviously I can use <code>os.system</code> to run the shell command, but surely there is a nice tidy, Python interface ...
12
2009-11-03T13:10:07Z
34,812,552
<p>You can use Python bindings for <code>libmount</code> from <a href="https://en.wikipedia.org/wiki/Util-linux" rel="nofollow">util-linux</a> project:</p> <pre><code>import pylibmount as mnt cxt = mnt.Context() cxt.source = '/dev/sda1' cxt.target = '/mnt/' cxt.mount() </code></pre> <p>For more information see this ...
2
2016-01-15T13:50:02Z
[ "python", "unix" ]
Python: Removing characters from beginnings of sequences in fasta format
1,667,341
<p>I have sequences in fasta format that contains primers of 17 bp at the beginning of the sequences. And the primers sometimes have mismatches. I therefore want to remove the first 17 chars of the sequences, except from the fasta header.</p> <p>The sequences look like this:</p> <pre><code>&gt; name_name_number_etc S...
1
2009-11-03T13:29:16Z
1,667,404
<p>If your file looks like</p> <pre><code>&gt;MCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTID FPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAELRHVMTNLGEKLTDEEVDEMIREA DIDGDGQVNYEEFVQMMTAK* </code></pre> <p>and you want to remove the first 17 chars o...
0
2009-11-03T13:42:20Z
[ "python", "extract", "character", "sequences", "fasta" ]
Python: Removing characters from beginnings of sequences in fasta format
1,667,341
<p>I have sequences in fasta format that contains primers of 17 bp at the beginning of the sequences. And the primers sometimes have mismatches. I therefore want to remove the first 17 chars of the sequences, except from the fasta header.</p> <p>The sequences look like this:</p> <pre><code>&gt; name_name_number_etc S...
1
2009-11-03T13:29:16Z
1,667,684
<pre><code>with open('fasta_file') as f: for line in f: if not line.startswith('&gt;'): print line[17:] </code></pre>
0
2009-11-03T14:31:11Z
[ "python", "extract", "character", "sequences", "fasta" ]
Python: Removing characters from beginnings of sequences in fasta format
1,667,341
<p>I have sequences in fasta format that contains primers of 17 bp at the beginning of the sequences. And the primers sometimes have mismatches. I therefore want to remove the first 17 chars of the sequences, except from the fasta header.</p> <p>The sequences look like this:</p> <pre><code>&gt; name_name_number_etc S...
1
2009-11-03T13:29:16Z
1,667,740
<p>If I understand correctly, you have to remove the primer only from the first 17 characters of a potentially multiline sequence. What you ask is a bit more difficult. Yes, a simple solution exists, but it can fail in some situations.</p> <p>My suggestion is: use <a href="http://biopython.org" rel="nofollow">Biopytho...
1
2009-11-03T14:39:35Z
[ "python", "extract", "character", "sequences", "fasta" ]
Accessing POST params with same name in python
1,667,349
<p>I need to get values of these check boxes with same name through HTTP "POST".</p> <pre><code>&lt;input type="checkbox" id="dde" name="dept[]" value="dde"/&gt; &lt;input type="checkbox" id="dre" name="dept[]" value="dre"/&gt; &lt;input type="checkbox" id="iid" name="dept[]" value="iid"/&gt; </code></pre> <p>How to ...
0
2009-11-03T13:31:44Z
1,667,393
<p>You can use <code>request.get_all()</code>. </p> <p>According to <a href="http://code.google.com/appengine/docs/python/tools/webapp/requestclass.html#Request%5Fget%5Fall" rel="nofollow" title="the docs">the docs</a> it "Returns a list of values of all of the query (URL) or POST arguments with the given name, possi...
4
2009-11-03T13:40:04Z
[ "python", "http", "google-app-engine" ]
Visibility_notify event in pyGTK
1,667,525
<p>I am on windows and I am developing a pygtk app. I need to know when a window is visible or hidden by another window. In order to stop an heavy drawing process.</p> <p><a href="http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--visibility-notify-event" rel="nofollow">http://www.pygtk.org/docs/py...
1
2009-11-03T14:08:04Z
1,668,258
<p>It's quite likely that the underlying GDK layer simply isn't "good enough" on Windows. The GTK+ toolkit's port to Windows is known to be a bit lagging in functionality and polish.</p> <p>If you can try the same program on a Linux machine, and it works there, you can be pretty certain this is a limitation of the Win...
2
2009-11-03T16:00:33Z
[ "python", "pygtk" ]
Best way to convert HTML to plaintext using Python
1,668,081
<p>I'm working on a project that involves converting a large amount of HTML content to plain/text. I have a custom-written module that does the job OK, but I'm wondering if there's some standard tools to help get the job done.</p>
9
2009-11-03T15:33:48Z
1,668,102
<p><a href="http://www.aaronsw.com/2002/html2text/">Html2Text</a> seems to be a good option</p>
8
2009-11-03T15:37:28Z
[ "python", "html", "plaintext" ]
Best way to convert HTML to plaintext using Python
1,668,081
<p>I'm working on a project that involves converting a large amount of HTML content to plain/text. I have a custom-written module that does the job OK, but I'm wondering if there's some standard tools to help get the job done.</p>
9
2009-11-03T15:33:48Z
1,668,118
<p>Here's a python library which does HTML parsing:</p> <ul> <li><a href="http://codespeak.net/lxml/lxmlhtml.html" rel="nofollow">lxml.html</a></li> </ul> <p><a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> is another option.</p>
4
2009-11-03T15:39:30Z
[ "python", "html", "plaintext" ]
How to de-import a Python module?
1,668,223
<p>I am in the process of coding an app which has to get the metadata (author,version..etc) out of several modules (.py files) and display them. The user selects a script and the script is executed. (New scripts can be added and old ones be taken of from the target folder just like a plugin system).</p> <p>Firstly I...
30
2009-11-03T15:55:05Z
1,668,289
<p>i think <a href="http://mail.python.org/pipermail/tutor/2006-August/048596.html">this post</a> should help you</p> <p>edit: to secure the availability of this information (in case the link dies or something similar) i will include the original message from the <a href="http://mail.python.org/mailman/listinfo/tutor"...
14
2009-11-03T16:05:14Z
[ "python" ]
How to de-import a Python module?
1,668,223
<p>I am in the process of coding an app which has to get the metadata (author,version..etc) out of several modules (.py files) and display them. The user selects a script and the script is executed. (New scripts can be added and old ones be taken of from the target folder just like a plugin system).</p> <p>Firstly I...
30
2009-11-03T15:55:05Z
1,670,649
<p>Suggestion: Import your modules dynamically using <code>__import__</code></p> <p>E.g.</p> <pre><code>module_list = ['os', 'decimal', 'random'] for module in module_list: x = __import__(module) print 'name: %s - module_obj: %s' % (x.__name__, x) </code></pre> <p>Will produce:</p> <pre><code>name: os - mod...
3
2009-11-03T22:45:40Z
[ "python" ]
How to de-import a Python module?
1,668,223
<p>I am in the process of coding an app which has to get the metadata (author,version..etc) out of several modules (.py files) and display them. The user selects a script and the script is executed. (New scripts can be added and old ones be taken of from the target folder just like a plugin system).</p> <p>Firstly I...
30
2009-11-03T15:55:05Z
12,046,009
<p>I know this post has been out of date but I just encountered this issue and was struggling against it for the past few days. Now I came with a conclusion that can perfectly solve this issue. Please see the sample code below:</p> <pre><code>try: theMod = sys.modules['ModNeedToBeDel'] except: theMod = None...
1
2012-08-20T22:17:31Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,668,616
<p>Consider:</p> <pre><code>&gt;&gt;&gt; nums = ((1, 2, 3, 4), (1, 5, 6), (19, 20, 24, 29, 400)) &gt;&gt;&gt; flat = [[(x - i) for i, x in enumerate(tu)] for tu in nums] &gt;&gt;&gt; print flat [[1, 1, 1, 1], [1, 4, 4], [19, 19, 22, 26, 396]] &gt;&gt;&gt; import itertools &gt;&gt;&gt; print sum(1 for tu in flat for _ ...
9
2009-11-03T16:49:22Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,668,644
<p>This could probably be put together in a more compact form, but I think clarity would suffer:</p> <pre><code>def pairs(seq): for i in range(1,len(seq)): yield (seq[i-1], seq[i]) def isadjacent(pair): return pair[0]+1 == pair[1] def sumrange(seq): return 1 + sum([1 for pair in pairs(seq) if not...
0
2009-11-03T16:53:03Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,668,657
<p>You could probably do this better if you had an <a href="http://pypi.python.org/pypi/interval/1.0.0" rel="nofollow">IntervalSet class</a> because then you would scan through your ranges to build your IntervalSet, then just use the count of set members.</p> <p>Some tasks don't always lend themselves to neat code, pa...
0
2009-11-03T16:54:40Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,668,697
<p>Just to show something closer to your original code:</p> <pre><code>def sumranges(nums): return sum( (1 for i in nums for j, v in enumerate(i) if j == 0 or v != i[j-1] + 1) ) </code></pre> <p>The idea here was to:</p> <ul> <li>avoid building intermediate lists but use a g...
7
2009-11-03T16:59:11Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,668,796
<p>My 2 cents:</p> <pre><code>&gt;&gt;&gt; sum(len(set(x - i for i, x in enumerate(t))) for t in nums) 7 </code></pre> <p>It's basically the same idea as descriped in <a href="http://stackoverflow.com/questions/1668491#answer-1668616">Alex' post</a>, but using a <code>set</code> instead of <code>itertools.groupby</co...
14
2009-11-03T17:12:07Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,668,844
<p>There is a formula for this, the sum of the first n numbers, 1+ 2+ ... + n = n(n+1) / 2 . Then if you want to have the sum of i-j then it is (j(j+1)/2) - (i(i+1)/2) this I am sure simplifies but you can work that out. It might not be pythonic but it is what I would use.</p>
0
2009-11-03T17:18:31Z
[ "python" ]
Summing Consecutive Ranges Pythonically
1,668,491
<p>I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate:</p> <pre><code>def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for ...
7
2009-11-03T16:32:30Z
1,669,129
<p>Here's my attempt:</p> <pre><code>def ranges(ls): for l in ls: consec = False for (a,b) in zip(l, l[1:]+(None,)): if b == a+1: consec = True if b is not None and b != a+1: consec = False if consec: yield 1 ''' &...
1
2009-11-03T18:09:51Z
[ "python" ]
Where does Python first look for files?
1,668,594
<p>I'm trying to learn how to parse .txt files in Python. This has led me to opening the interpreter (terminal > python) and playing around. However, I can't seem to be able to specify the right path. Where does Python first look?</p> <p>This is my first step:</p> <pre><code> f = open("/Desktop/temp/myfile.txt","f...
3
2009-11-03T16:46:25Z
1,668,612
<p>Edit: Oh and yes, your second argument is wrong. Didn't even notice that :)</p> <p>Python looks where you tell it to for file opening. If you open up the interpreter in /home/malcmcmul then that will be the active directory.</p> <p>If you specify a path, that's where it looks. Are you sure /Desktop/temp is a valid...
7
2009-11-03T16:48:54Z
[ "python", "file" ]
Where does Python first look for files?
1,668,594
<p>I'm trying to learn how to parse .txt files in Python. This has led me to opening the interpreter (terminal > python) and playing around. However, I can't seem to be able to specify the right path. Where does Python first look?</p> <p>This is my first step:</p> <pre><code> f = open("/Desktop/temp/myfile.txt","f...
3
2009-11-03T16:46:25Z
1,668,622
<p>To begin with, the second argument is the permissions bit: "r" for read, "w" for write, "a" for append. "file1" shouldn't be there.</p>
2
2009-11-03T16:50:23Z
[ "python", "file" ]
Where does Python first look for files?
1,668,594
<p>I'm trying to learn how to parse .txt files in Python. This has led me to opening the interpreter (terminal > python) and playing around. However, I can't seem to be able to specify the right path. Where does Python first look?</p> <p>This is my first step:</p> <pre><code> f = open("/Desktop/temp/myfile.txt","f...
3
2009-11-03T16:46:25Z
1,668,623
<p>That doesn't work as you've got the wrong syntax for <code>open</code>.</p> <p>At the interpreter prompt try this:</p> <pre><code>&gt;&gt;&gt; help(open) Help on built-in function open in module __builtin__: open(...) open(name[, mode[, buffering]]) -&gt; file object Open a file using the file() type, re...
8
2009-11-03T16:50:53Z
[ "python", "file" ]
Where does Python first look for files?
1,668,594
<p>I'm trying to learn how to parse .txt files in Python. This has led me to opening the interpreter (terminal > python) and playing around. However, I can't seem to be able to specify the right path. Where does Python first look?</p> <p>This is my first step:</p> <pre><code> f = open("/Desktop/temp/myfile.txt","f...
3
2009-11-03T16:46:25Z
1,668,629
<p>Try:</p> <pre><code>f = open('Desktop/temp/myfile.txt', 'r') </code></pre> <p>This will open file relatively to current directory. You can use <code>'/Desktop/temp/myfile.txt'</code> if you want to open file using absolute path. Second parameter to open function is mode (don't know what <code>file1</code> should m...
2
2009-11-03T16:51:21Z
[ "python", "file" ]
Where does Python first look for files?
1,668,594
<p>I'm trying to learn how to parse .txt files in Python. This has led me to opening the interpreter (terminal > python) and playing around. However, I can't seem to be able to specify the right path. Where does Python first look?</p> <p>This is my first step:</p> <pre><code> f = open("/Desktop/temp/myfile.txt","f...
3
2009-11-03T16:46:25Z
1,698,523
<p>This:</p> <pre><code>import os os.path </code></pre> <p>should tell you where python looks first. Of course, if you specify absolute paths (as you have), then this should not matter.</p> <p>Also, as everyone else has said, your second argument in open is wrong. To find the proper way of doing it, try this code:</...
-1
2009-11-09T00:42:38Z
[ "python", "file" ]
order_with_respect_to() Child relationship
1,668,742
<p>I'm trying to figure out how I can use: order_with_respect_to() to order via a Child relationship</p> <pre><code>class Product(models.Model): name = models.CharField(max_length=100) class Affiliate(models.Model): product = models.ForeignKey(Product) clicks = models.IntegerField(default=0) </code></pre...
0
2009-11-03T17:06:23Z
1,671,043
<p>Take a look at aggregates (<a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/db/aggregation/</a>). I think you can use them to help you with this problem.</p>
1
2009-11-04T00:32:47Z
[ "python", "django" ]
order_with_respect_to() Child relationship
1,668,742
<p>I'm trying to figure out how I can use: order_with_respect_to() to order via a Child relationship</p> <pre><code>class Product(models.Model): name = models.CharField(max_length=100) class Affiliate(models.Model): product = models.ForeignKey(Product) clicks = models.IntegerField(default=0) </code></pre...
0
2009-11-03T17:06:23Z
5,268,892
<p>See <code>order_with_respect_to</code> documentation <a href="http://docs.djangoproject.com/en/dev/ref/models/options/#order-with-respect-to" rel="nofollow">here</a>, updated since this question was posted.</p>
0
2011-03-11T04:17:13Z
[ "python", "django" ]
Extending forms.SelectMultiple Without Losing Values
1,668,881
<p>I have a model form that I am writing a custom widget for in order to replace the many-to-many forms.SelectMultiple fields with jQuery FCBKcomplete widgets. While the replacement of the multiselect element works fine, it is no longer pulling the options for the multiselect.</p> <p>Here is my widget:</p> <pre><code...
0
2009-11-03T17:25:43Z
4,014,843
<p>1 year passed, but answer may be valuable even with current django version. </p> <p>Reason for such behavior seems to missing CHOICES property for fcbk fields just push choices to the Form </p> <pre><code>class EmailSubscriptionFilterForm(forms.ModelForm): class Meta: model = EmailSubscription ...
0
2010-10-25T13:12:21Z
[ "python", "django", "django-forms" ]
Python: importing through function to main namespace
1,668,882
<p>(Important: See update below.)</p> <p>I'm trying to write a function, <code>import_something</code>, that will important certain modules. (It doesn't matter which for this question.) The thing is, I would like those modules to be imported at the level from which the function is called. For example:</p> <pre><code>...
4
2009-11-03T17:25:49Z
1,668,945
<p>Functions have the ability to return something to where they were called. Its called their return value :p</p> <pre><code>def import_something(): # decide what to import # ... mod = __import__( something ) return mod my_module = import_something() my_module.do_stuff() </code></pre> <p>good style, n...
4
2009-11-03T17:35:08Z
[ "python", "import" ]
Python: importing through function to main namespace
1,668,882
<p>(Important: See update below.)</p> <p>I'm trying to write a function, <code>import_something</code>, that will important certain modules. (It doesn't matter which for this question.) The thing is, I would like those modules to be imported at the level from which the function is called. For example:</p> <pre><code>...
4
2009-11-03T17:25:49Z
1,668,977
<p>According to <code>__import__</code>'s help:</p> <pre><code>__import__(name, globals={}, locals={}, fromlist=[], level=-1) -&gt; module Import a module. The globals are only used to determine the context; they are not modified. ... </code></pre> <p>So you can simply get the globals of your parent frame and use t...
0
2009-11-03T17:39:38Z
[ "python", "import" ]
Python: importing through function to main namespace
1,668,882
<p>(Important: See update below.)</p> <p>I'm trying to write a function, <code>import_something</code>, that will important certain modules. (It doesn't matter which for this question.) The thing is, I would like those modules to be imported at the level from which the function is called. For example:</p> <pre><code>...
4
2009-11-03T17:25:49Z
1,668,996
<p>You can monkey with the parent frame in CPython to install the modules into the locals for that frame (and only that frame). The downsides are that a) this is really quite hackish and b) sys._getframe() is not guaranteed to exist in other python implementations.</p> <pre><code>def importer(): f = sys._getframe(1...
1
2009-11-03T17:44:14Z
[ "python", "import" ]
Python: importing through function to main namespace
1,668,882
<p>(Important: See update below.)</p> <p>I'm trying to write a function, <code>import_something</code>, that will important certain modules. (It doesn't matter which for this question.) The thing is, I would like those modules to be imported at the level from which the function is called. For example:</p> <pre><code>...
4
2009-11-03T17:25:49Z
1,669,145
<p>Are you looking for something like this?</p> <pre><code>def my_import(*names): for name in names: sys._getframe(1).f_locals[name] = __import__(name) </code></pre> <p>then you can call it like this:</p> <pre><code>my_import("os", "re") </code></pre> <p>or</p> <pre><code>namelist = ["os", "re"] my_imp...
1
2009-11-03T18:12:32Z
[ "python", "import" ]
Filtering by dates in Google App Engine's Datastore
1,668,963
<p>I'm having some issues trying to filter a set of objets by their date. Right now I can get all of a user's transactions like this:</p> <pre><code>&gt; t = Transaction.all().filter("client_email =", "some_email").filter("application_id =", "foo").fetch(100) &gt; len(t) # =&gt; 4 </code></pre> <p>Now, if I want to s...
2
2009-11-03T17:37:38Z
12,701,918
<p>Have you tried making the query date info compliant with <a href="https://developers.google.com/appengine/docs/python/datastore/gqlreference#Syntax" rel="nofollow">App Engine GQL syntax</a>?. E.g syntax:</p> <pre><code>DATETIME(year, month, day, hour, minute, second) DATETIME('YYYY-MM-DD HH:MM:SS') DATE(year, month...
1
2012-10-03T04:29:36Z
[ "python", "google-app-engine" ]
Reading bytestreams in Python
1,669,040
<p>I'm using Python appscript to write artwork to my iTunes Songs. I have a file stored in .pict format and when i use the normal open and read() routines, it reads the content as a string (encoded in utf-8). </p> <pre><code>imFile = open('/Users/kartikaiyer/temp.pict','r') data = imFile.read() it = app('iTunes') sel ...
1
2009-11-03T17:52:11Z
1,669,074
<p>Try setting the read mode to binary:</p> <pre><code>imFile = open('/Users/kartikaiyer/temp.pict','rb') </code></pre>
7
2009-11-03T17:59:38Z
[ "python", "appscript" ]
Python auto define variables
1,670,252
<p>I am new to programming and am learning Python as my first language. I have been tasked with writing a script that converts one input file type to another. My problem is this: There is one part of the input files where there can be any number of rows of data. I wrote a loop to determine how many rows there are but c...
1
2009-11-03T21:29:47Z
1,670,285
<p>That is something you really don't want. Suppose you have those variables rprim1, rprim2 .. etc how would you know how many of them do you have?</p> <p>Read up on lists in python <a href="http://docs.python.org/tutorial/datastructures.html" rel="nofollow">link text</a></p>
1
2009-11-03T21:34:33Z
[ "python", "variables" ]
Python auto define variables
1,670,252
<p>I am new to programming and am learning Python as my first language. I have been tasked with writing a script that converts one input file type to another. My problem is this: There is one part of the input files where there can be any number of rows of data. I wrote a loop to determine how many rows there are but c...
1
2009-11-03T21:29:47Z
1,670,286
<p>You <em>can</em> dynamically create the variables, but it doesn't make sense unless this is homework.</p> <p>instead use</p> <pre><code>rprim=infile.readlines() </code></pre> <p>then the lines are </p> <pre><code>rprim[0], rprim[1], rprim[2], rprim[3], rprim[4], rprim[5], rprim[6] </code></pre> <p>you can find ...
13
2009-11-03T21:34:45Z
[ "python", "variables" ]
How can I get pyplot images to show on a console app?
1,670,480
<p>I'm trying to create an image using <code>matplotlib.pyplot.imshow()</code>. However, when I run the program from my console, it doesn't display anything?</p> <p>This is the code:</p> <pre><code>import matplotlib.pyplot myimage = gen_image() matplotlib.pyplot.gray() matplotlib.pyplot.imshow(results) </code></pr...
6
2009-11-03T22:14:37Z
1,670,595
<p>You have to call the <code>show</code> function to actually display anything, like</p> <pre><code>matplotlib.pyplot.show() </code></pre> <p>Unfortunately the matplotlib documentation seems to be currently broken, so I can't provide a link.</p> <p>Note that for interactive plotting one typically uses IPython, whic...
5
2009-11-03T22:35:21Z
[ "python", "image", "console", "matplotlib" ]
How can I get pyplot images to show on a console app?
1,670,480
<p>I'm trying to create an image using <code>matplotlib.pyplot.imshow()</code>. However, when I run the program from my console, it doesn't display anything?</p> <p>This is the code:</p> <pre><code>import matplotlib.pyplot myimage = gen_image() matplotlib.pyplot.gray() matplotlib.pyplot.imshow(results) </code></pr...
6
2009-11-03T22:14:37Z
1,670,628
<p>You could try <a href="http://fishsoup.net/software/reinteract/" rel="nofollow">http://fishsoup.net/software/reinteract/</a></p>
0
2009-11-03T22:40:54Z
[ "python", "image", "console", "matplotlib" ]
Changing web service url in SUDS library
1,670,569
<p>Using SUDS SOAP client how do I specify web service URL. I can see clearly that WSDL path is specified in Client constructor but what if I wan't to change web service url?</p>
2
2009-11-03T22:31:35Z
1,670,775
<p>I think you have to create a new Client object for each different URL.</p>
1
2009-11-03T23:15:32Z
[ "python", "soap", "suds" ]
Changing web service url in SUDS library
1,670,569
<p>Using SUDS SOAP client how do I specify web service URL. I can see clearly that WSDL path is specified in Client constructor but what if I wan't to change web service url?</p>
2
2009-11-03T22:31:35Z
2,106,871
<p>Suds supports <a href="https://fedorahosted.org/suds/wiki/Documentation#WSDLWITHMULTIPLESERVICESMULTIPLEPORTS" rel="nofollow">WSDL with multiple services or multiple ports</a> (or both), and without having any detailed information on what you're working with, I am only <em>guessing</em> that this is what you are loo...
4
2010-01-21T04:10:16Z
[ "python", "soap", "suds" ]
Changing web service url in SUDS library
1,670,569
<p>Using SUDS SOAP client how do I specify web service URL. I can see clearly that WSDL path is specified in Client constructor but what if I wan't to change web service url?</p>
2
2009-11-03T22:31:35Z
2,123,294
<p>You can point the client to different endpoints via two methods: </p> <p>1) client.set_options(location='http://path/to/your/wsdl') -or- 2) using the client's clone() method. Then use set_options() again. It's really the same as #1 above but you end up with two clients to use, not one.</p> <p>This latter method i...
2
2010-01-23T13:36:25Z
[ "python", "soap", "suds" ]
python chat client lib
1,670,735
<p>I'm trying to write a Python lib that will implement the client side of a certain chat protocol. </p> <p>After I connect to the server,<br> I start the main loop where I read from the server and handle received commands and here I need to call a callback function (like <code>on_message</code> or <code>on file_rece...
0
2009-11-03T23:05:01Z
1,670,779
<p>For a python app doing this, I wouldn't use threads. I would use a framework like <a href="http://twistedmatrix.com">Twisted</a>.</p> <p>The docs have examples; <a href="http://twistedmatrix.com/projects/core/documentation/examples/#auto1">here's a chat example</a>.</p>
6
2009-11-03T23:17:16Z
[ "python", "multithreading", "chat" ]
python chat client lib
1,670,735
<p>I'm trying to write a Python lib that will implement the client side of a certain chat protocol. </p> <p>After I connect to the server,<br> I start the main loop where I read from the server and handle received commands and here I need to call a callback function (like <code>on_message</code> or <code>on file_rece...
0
2009-11-03T23:05:01Z
1,671,922
<p>I would use the select module, or alternately twisted, however select is a bit more portable, and to my mind somewhat more pythonic.</p>
2
2009-11-04T06:00:39Z
[ "python", "multithreading", "chat" ]
python chat client lib
1,670,735
<p>I'm trying to write a Python lib that will implement the client side of a certain chat protocol. </p> <p>After I connect to the server,<br> I start the main loop where I read from the server and handle received commands and here I need to call a callback function (like <code>on_message</code> or <code>on file_rece...
0
2009-11-03T23:05:01Z
1,672,945
<p>Threads are just an unnecessary complication here and will lead to obscure bugs if you're not familiar with how to use them correctly. <a href="http://docs.python.org/library/asyncore.html" rel="nofollow">asyncore</a> or <a href="http://docs.python.org/library/asynchat.html" rel="nofollow">asynchat</a> are simple ro...
1
2009-11-04T10:33:06Z
[ "python", "multithreading", "chat" ]
How to upload huge files from Nokia 95 to webserver?
1,670,944
<p>I'm trying to upload a huge file from my Nokia N95 mobile to my webserver using Pys60 python code. However the code crashes because I'm trying to load the file into memory and trying to post to a HTTP url. Any idea how to upload huge files > 120 MB to webserver using Pys60.</p> <p>Following is the code I use to sen...
0
2009-11-03T23:59:10Z
1,670,956
<p>You can't. It's pretty much physically impossible. You'll need to split the file into small chunks and upload it bit by bit, which is very difficult to do quickly and efficiently on that sort of platform.</p> <p>Jamie</p>
0
2009-11-04T00:01:29Z
[ "python", "http", "post", "file-upload", "pys60" ]
How to upload huge files from Nokia 95 to webserver?
1,670,944
<p>I'm trying to upload a huge file from my Nokia N95 mobile to my webserver using Pys60 python code. However the code crashes because I'm trying to load the file into memory and trying to post to a HTTP url. Any idea how to upload huge files > 120 MB to webserver using Pys60.</p> <p>Following is the code I use to sen...
0
2009-11-03T23:59:10Z
1,670,959
<p>You'll need to craft a client code to split your source file in small chunks and rebuild that pieces server-side.</p>
0
2009-11-04T00:02:16Z
[ "python", "http", "post", "file-upload", "pys60" ]
How to upload huge files from Nokia 95 to webserver?
1,670,944
<p>I'm trying to upload a huge file from my Nokia N95 mobile to my webserver using Pys60 python code. However the code crashes because I'm trying to load the file into memory and trying to post to a HTTP url. Any idea how to upload huge files > 120 MB to webserver using Pys60.</p> <p>Following is the code I use to sen...
0
2009-11-03T23:59:10Z
1,672,521
<p>where does this <code>post_multipart()</code> function comes from ? </p> <p>if it is from <a href="http://codespeak.net/py/dist/apigen/source/test/web/post%5Fmultipart.py.html" rel="nofollow">here</a>, then it should be easy to adapt the code so that it takes a file object in argument and not the full content of th...
0
2009-11-04T09:05:28Z
[ "python", "http", "post", "file-upload", "pys60" ]
Namespace-respecting relative import in Python
1,671,362
<p>I have this folder structure:</p> <pre><code>package/ __init__.py misc/ __init__.py tools.py subpackage/ __init__.py submodule.py </code></pre> <p>I am in <code>submodule.py</code>, and I would like to import <code>misc.tools</code>. I don't want to use absolute import t...
3
2009-11-04T02:19:06Z
1,671,425
<p>What about...:</p> <pre><code>from .. import misc from ..misc import tools as _ print misc.tools.__file__ </code></pre> <p>This makes <code>misc.tools</code> available, as the <code>print</code> confirms, and with the right name and contents.</p> <p>Inevitably, it <em>also</em> binds the same module to some bare...
5
2009-11-04T02:40:07Z
[ "python", "import", "relative-path" ]
feedparser and Google News
1,671,428
<p>I'm trying to download a corpus of news (to try to do some natural language processing) from Google News using the universal feedparser with python. I really know nothing of XML, I'm just using an example of how to use the feedparser. The problem is that I can't find in the dict I get from the RSS feed the <em>conte...
3
2009-11-04T02:41:40Z
1,671,438
<p>First you need to check out <a href="http://cyber.law.harvard.edu/rss/rss.html" rel="nofollow">RSS Specification</a>. And here is a <a href="http://www.feedparser.org/" rel="nofollow">feed parser</a>. That should get you started. </p>
1
2009-11-04T02:46:31Z
[ "python", "rss", "news", "feedparser" ]
feedparser and Google News
1,671,428
<p>I'm trying to download a corpus of news (to try to do some natural language processing) from Google News using the universal feedparser with python. I really know nothing of XML, I'm just using an example of how to use the feedparser. The problem is that I can't find in the dict I get from the RSS feed the <em>conte...
3
2009-11-04T02:41:40Z
1,671,447
<p>Have you examined the feed from Google News?</p> <p>There is a root element in each feed which contains a bunch of information and the actual entries dict. Here's a dirty way to see what's available:</p> <pre><code>import feedparser d = feedparser.parse('http://news.google.com/news?pz=1&amp;cf=all&amp;ned=ca&amp;h...
6
2009-11-04T02:50:01Z
[ "python", "rss", "news", "feedparser" ]
web chart with hover events
1,671,520
<p>I am after a library with a Python interface to render nice looking charts with hover events for each point.</p> <p><a href="http://www.advsofteng.com/gallery.html" rel="nofollow">ChartDirector</a> does what I want, but I would prefer an open source solution. <a href="http://teethgrinder.co.uk/open-flash-chart-2/" ...
3
2009-11-04T03:21:09Z
1,672,854
<p>Not strictly Python, but you may want to look at <a href="http://code.google.com/p/flot/" rel="nofollow">Flot</a>. (assuming by web chart you mean those that are to be embedded on web pages)</p>
2
2009-11-04T10:19:11Z
[ "python", "graph", "hover", "charts" ]
How can I change a list of strings into CSV in Python?
1,671,786
<h3>Example strings:</h3> <pre><code>uji708 uhodih utus29 agamu4 azi340 ekon62 </code></pre> <p>I need to change them into CSV list like this:</p> <pre><code>uji708,uhodih,utus29, agamu4,azi340,ekon62, </code></pre> <p>My code so far:</p> <pre><code>email = 'mail_list.txt' handle = open(email) for line in handl...
0
2009-11-04T05:12:06Z
1,671,994
<p>Here is a very specific answer to a very specific question when you will clarify/generalize your question I may update my answer</p> <pre><code>s = """ uji708 uhodih utus29 agamu4 azi340 ekon62 """ l = s.split() print '\n'.join((','.join(x) for x in zip(l[::3], l[1::3], l[2::3]))) </code></pre>
0
2009-11-04T06:24:28Z
[ "python" ]
How can I change a list of strings into CSV in Python?
1,671,786
<h3>Example strings:</h3> <pre><code>uji708 uhodih utus29 agamu4 azi340 ekon62 </code></pre> <p>I need to change them into CSV list like this:</p> <pre><code>uji708,uhodih,utus29, agamu4,azi340,ekon62, </code></pre> <p>My code so far:</p> <pre><code>email = 'mail_list.txt' handle = open(email) for line in handl...
0
2009-11-04T05:12:06Z
1,681,364
<p>Use csv.writer:</p> <pre><code>import csv import sys writer = csv.csvwriter(sys.stdout) writer.writerow(iterable_containing_my_strings) </code></pre>
2
2009-11-05T15:40:04Z
[ "python" ]
Decorating Instance Methods in Python
1,672,064
<p>Here's the gist of what I'm trying to do. I have a list of objects, and I know they have an instance method that looks like:</p> <pre><code>def render(self, name, value, attrs) # Renders a widget... </code></pre> <p>I want to (essentialy) decorate these functions at runtime, as I'm iterating over the list of ob...
3
2009-11-04T06:50:58Z
1,672,094
<pre><code>def decorate_method(f): def wrapper(self, name, value, attrs): self.attrs = attrs return f(self, name, value, attrs) return wrapper def decorate_class(c): for n in dir(c): f = getattr(c, n) if hasattr(f, 'im_func'): setattr(c, n, decorate_method(f.im_func)) </code></pre> <p>You'...
7
2009-11-04T06:59:36Z
[ "python", "django", "class", "decorator", "instance" ]
Decorating Instance Methods in Python
1,672,064
<p>Here's the gist of what I'm trying to do. I have a list of objects, and I know they have an instance method that looks like:</p> <pre><code>def render(self, name, value, attrs) # Renders a widget... </code></pre> <p>I want to (essentialy) decorate these functions at runtime, as I'm iterating over the list of ob...
3
2009-11-04T06:50:58Z
1,672,197
<p>The "classic" way is to subclass. This way you don't have to mess with other peoples classes.</p> <pre><code>class someclass(object): def render(self, name, value, attrs): print hasattr(self, 'attrs') class my_render(object): def render(self, name, value, attrs): self.attrs = attrs # kind o...
3
2009-11-04T07:28:53Z
[ "python", "django", "class", "decorator", "instance" ]
DBus Python Problems
1,672,113
<p>When I'm trying to get the idle time of the gnome screensaver in seconds, through dbus, python throws an TypeError.</p> <p>In the documentation I found for the screensaver sessionIdleTime, it returns a unsigned integer. <a href="http://www.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html#gs-method-Ge...
1
2009-11-04T07:04:23Z
1,673,464
<p><code>str(gs.GetSessionIdleTime())</code> cast the integer into a string.</p> <p>And after that, using + in a string variable incorporated it into another dbus call that was called by the output.</p>
0
2009-11-04T12:23:41Z
[ "python", "gnome", "dbus" ]
text-mine PDF files with Python?
1,672,202
<p>Is there a package/library for python that would allow me to open a PDF, and search the text for certain words?</p>
4
2009-11-04T07:30:02Z
1,672,226
<p>I don't think you can do it in one step, but you can certainly get the text out of a pdf with <a href="http://www.unixuser.org/~euske/python/pdfminer/index.html" rel="nofollow">pdfminer</a>. Then you can apply whatever text search to that recovered data.</p>
4
2009-11-04T07:38:39Z
[ "python", "pdf", "text-mining" ]
text-mine PDF files with Python?
1,672,202
<p>Is there a package/library for python that would allow me to open a PDF, and search the text for certain words?</p>
4
2009-11-04T07:30:02Z
1,672,230
<p>Using <a href="https://github.com/mstamy2/PyPDF2/" rel="nofollow">PyPdf2</a> you can use <a href="http://code.activestate.com/recipes/511465/" rel="nofollow">extractText()</a> method to extract pdf text and work on it.</p> <p>Update: Changed text to refer to PyPdf2, thanks to @Aditya Kumar for heads up.</p>
11
2009-11-04T07:39:34Z
[ "python", "pdf", "text-mining" ]
Loading a simple Qt Designer form in to Pyside
1,672,271
<p>I create a simple form in Qt designer and am trying to load it in to a Qt application I'm creating with PySide but without much luck.</p> <p>Here's the generated code from `pyside-uic':</p> <pre><code># -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'clientEditorForm.ui' # # Created: T...
10
2009-11-04T07:51:26Z
1,681,374
<p>Firstly you are using PySide(Nokia) not PyQt4(Riverbank Computing), although their API's are nearly identical they are not the same project. The PySide examples are available here: git clone git://gitorious.org/pyside/pyside-examples.git</p> <p>I think the problem may have to do with your call of </p> <pre><code>s...
4
2009-11-05T15:41:43Z
[ "python", "qt4", "pyside" ]
Loading a simple Qt Designer form in to Pyside
1,672,271
<p>I create a simple form in Qt designer and am trying to load it in to a Qt application I'm creating with PySide but without much luck.</p> <p>Here's the generated code from `pyside-uic':</p> <pre><code># -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'clientEditorForm.ui' # # Created: T...
10
2009-11-04T07:51:26Z
1,737,836
<p>Turns out there is a bug in PySide with the QSpacerItem class. Commenting out the QSpacerItem instances in the code above makes it work just fine. There's a bug report on the <a href="http://bugs.openbossa.org/show%5Fbug.cgi?id=92">PySide bugzilla</a>.</p>
5
2009-11-15T15:31:45Z
[ "python", "qt4", "pyside" ]
Reading from files in python
1,672,360
<p>I need to find out the maximum and minimum value in a line by reading a file and should be dividing the maximum value by the minimum value. Am interested to do this in python. </p> <p>the contents of the file (file.txt) looks like this..</p> <pre><code>A28102_at,151,263,88,484,118,270,458,872,62,194 AB000114_at,72...
0
2009-11-04T08:26:25Z
1,672,384
<p>As you are a beginner, I won't give a copy/paste code snippet; there is more to learn if you figure the details out yourself. But here's what you could do:</p> <ul> <li>read the file line-by-line in a loop, storing the current line in a string</li> <li>for each line, split the string on commas, resulting in a list<...
4
2009-11-04T08:31:34Z
[ "python", "file-io" ]
Reading from files in python
1,672,360
<p>I need to find out the maximum and minimum value in a line by reading a file and should be dividing the maximum value by the minimum value. Am interested to do this in python. </p> <p>the contents of the file (file.txt) looks like this..</p> <pre><code>A28102_at,151,263,88,484,118,270,458,872,62,194 AB000114_at,72...
0
2009-11-04T08:26:25Z
1,672,401
<p>I'm not sure if this is the most "pythonic" way of doing it, but it should work. I'm using lists instead of arrays.</p> <pre><code>for line in fp: tokens = line.split(',') # tokenize the line with comma as the only delimiter numbers = map(int, tokens[1:]) # skip the first value and convert to integer values...
3
2009-11-04T08:35:30Z
[ "python", "file-io" ]
Reading from files in python
1,672,360
<p>I need to find out the maximum and minimum value in a line by reading a file and should be dividing the maximum value by the minimum value. Am interested to do this in python. </p> <p>the contents of the file (file.txt) looks like this..</p> <pre><code>A28102_at,151,263,88,484,118,270,458,872,62,194 AB000114_at,72...
0
2009-11-04T08:26:25Z
1,672,411
<p>Python comes with batteries! Use the csv module to parse csv files:</p> <pre><code>#!/usr/bin/env python import csv csvobj=csv.reader(open('file.txt','r')) for datum in csvobj: datum=[float(val) for val in datum[1:]] print(datum) maximum=max(datum) minimum=min(datum) print(maximum/minimum) # [...
6
2009-11-04T08:38:24Z
[ "python", "file-io" ]
python and pyPdf - how to extract text from the pages so that there are spaces between lines
1,672,466
<p>currently, if I make a page object of a pdf page with pyPdf, and extractText(), what happens is that lines are concatenated together. For example, if line 1 of the page says "hello" and line 2 says "world" the resulting text returned from extractText() is "helloworld" instead of "hello world." Does anyone know how t...
5
2009-11-04T08:53:31Z
1,673,093
<p>This is a common problem with pdf parsing. You can also expect trailing dashes that you will have to fix in some cases. I came up with a workaround for one of my projects which I will describe here shortly:</p> <p>I used <a href="http://www.unixuser.org/~euske/python/pdfminer/index.html" rel="nofollow">pdfminer</a>...
2
2009-11-04T11:04:33Z
[ "python", "text", "formatting", "pypdf" ]
overloading __init__ of unittest.testcase
1,672,520
<p>I want to add two variables to my subclass which is inherited from unittest.testcase</p> <p>like I have:</p> <pre><code>import unittest class mrp_repair_test_case(unittest.TestCase): def __init__(self, a=None, b=None, methodName=['runTest']): unittest.TestCase.__init__(self) self.a...
4
2009-11-04T09:05:14Z
1,672,600
<p>At first glance, it looks like you need to create an instance of <code>mrp_repair_test_case</code>. Your current line:</p> <pre><code>mrp_repair_test_case(a=10,b=20) </code></pre> <p>doesn't actually do anything.</p> <p>Try (not tested):</p> <pre><code>def runtest(): m = mrp_repair_test_case(a=10, b=20) ...
6
2009-11-04T09:20:53Z
[ "python", "unit-testing" ]
How to generate graphical sitemap of large website
1,672,532
<p>I would like to generate a graphical sitemap for my website. There are two stages, as far as I can tell:</p> <ol> <li>crawl the website and analyse the link relationship to extract the tree structure </li> <li>generate a visually pleasing render of the tree</li> </ol> <p>Does anyone have advice or experience with ...
4
2009-11-04T09:07:59Z
1,672,651
<p><a href="http://www.example-code.com/python/pythonspider.asp" rel="nofollow">Here is a python web crawler</a>, which should make a good starting point. Your general strategy is this:</p> <ul> <li>you need to take care that outbound links are never followed, including links on the same domain but higher up than your...
3
2009-11-04T09:35:07Z
[ "python", "website", "sitemap", "web-crawler" ]
How to generate graphical sitemap of large website
1,672,532
<p>I would like to generate a graphical sitemap for my website. There are two stages, as far as I can tell:</p> <ol> <li>crawl the website and analyse the link relationship to extract the tree structure </li> <li>generate a visually pleasing render of the tree</li> </ol> <p>Does anyone have advice or experience with ...
4
2009-11-04T09:07:59Z
1,672,664
<p>The only automatic way to create a sitemap is to know the structure of your site and write a program which builds on that knowledge. Just crawling the links won't usually work because links can be between any pages so you get a graph (i.e. connections between nodes). There is no way to convert a graph into a tree in...
4
2009-11-04T09:39:10Z
[ "python", "website", "sitemap", "web-crawler" ]
How to generate graphical sitemap of large website
1,672,532
<p>I would like to generate a graphical sitemap for my website. There are two stages, as far as I can tell:</p> <ol> <li>crawl the website and analyse the link relationship to extract the tree structure </li> <li>generate a visually pleasing render of the tree</li> </ol> <p>Does anyone have advice or experience with ...
4
2009-11-04T09:07:59Z
1,673,933
<p>Please see <a href="http://aaron.oirt.rutgers.edu/myapp/docs/W1100%5F2200.TreeView" rel="nofollow">http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2200.TreeView</a> on how to format tree views. You can also probably modify the example application <a href="http://aaron.oirt.rutgers.edu/myapp/DirectoryTree/index" rel=...
1
2009-11-04T14:04:17Z
[ "python", "website", "sitemap", "web-crawler" ]
How to generate graphical sitemap of large website
1,672,532
<p>I would like to generate a graphical sitemap for my website. There are two stages, as far as I can tell:</p> <ol> <li>crawl the website and analyse the link relationship to extract the tree structure </li> <li>generate a visually pleasing render of the tree</li> </ol> <p>Does anyone have advice or experience with ...
4
2009-11-04T09:07:59Z
20,932,444
<p>For creating graphical sitemap of a website you can use <a href="http://site-visualizer.com/download" rel="nofollow" title="Site Visualizer">Site Visualizer</a> (Standard or Professional version). </p> <p>After installation, click Project -> New, type website URL you need to crawl, then click Start Crawl tool butto...
0
2014-01-05T10:23:16Z
[ "python", "website", "sitemap", "web-crawler" ]
How to generate graphical sitemap of large website
1,672,532
<p>I would like to generate a graphical sitemap for my website. There are two stages, as far as I can tell:</p> <ol> <li>crawl the website and analyse the link relationship to extract the tree structure </li> <li>generate a visually pleasing render of the tree</li> </ol> <p>Does anyone have advice or experience with ...
4
2009-11-04T09:07:59Z
30,061,761
<p>The DYNO Mapper (<a href="http://www.dynomapper.com" rel="nofollow">http://www.dynomapper.com</a>) visual sitemap generator can generate large graphical sitemaps for large websites and will export in HTML, XML, and PDFs. You can actually sort and filter your pages within your sitemap using Google Analytics metrics i...
0
2015-05-05T19:36:31Z
[ "python", "website", "sitemap", "web-crawler" ]
parse.unquote_plus TypeError
1,672,621
<p>I'm trying to format a file so that it can be inserted into a database, the file is originally compressed and arround 1.3MB big. Each line looks something like this:</p> <blockquote> <p>398,%7EAnoniem+001%7E,543,480,7525010,1775,0</p> </blockquote> <p>This is how the code looks like that parses this file:</p> <...
1
2009-11-04T09:26:29Z
1,672,796
<p>PROBLEM 1 is that urllib.unquote_plus doesn't like the <code>line</code> that you have fed it. The message should be "Please supply a str object" :-) I suggest that you fix problem 2 below, and insert:</p> <pre><code>print('line', type(line), repr(line)) </code></pre> <p>immediately after your <code>for</code> sta...
2
2009-11-04T10:05:50Z
[ "python", "parsing", "urllib", "typeerror" ]
parse.unquote_plus TypeError
1,672,621
<p>I'm trying to format a file so that it can be inserted into a database, the file is originally compressed and arround 1.3MB big. Each line looks something like this:</p> <blockquote> <p>398,%7EAnoniem+001%7E,543,480,7525010,1775,0</p> </blockquote> <p>This is how the code looks like that parses this file:</p> <...
1
2009-11-04T09:26:29Z
1,672,981
<pre><code>import gzip, os, urllib.parse archive_relpath = os.sep.join(map(str, Newest_Date[:4])) + ' village.gz' archive_path = os.path.join(Root, 'data', archive_relpath) with gzip.open(archive_path) as Village: Village_Parsed = ''.join(urllib.parse.unquote_plus(line.decode('ascii')) ...
0
2009-11-04T10:39:05Z
[ "python", "parsing", "urllib", "typeerror" ]
Why does python -V write to the error stream?
1,672,650
<p>I was writing a script to inspect python's version on my system and I've noticed that <code>python -V</code> writes to the error stream, while <code>python -h</code>, for instance, uses the standard output. Is there a good reason for this behavior?</p>
6
2009-11-04T09:34:36Z
1,673,079
<p>-h used to print to stderr too as you see here from main.c</p> <pre><code>usage(int exitcode, char* program) { fprintf(stderr, usage_line, program); fprintf(stderr, usage_top); fprintf(stderr, usage_mid); fprintf(stderr, usage_bot, DELIM, DELIM, PYTHONHOMEHELP); exit(exitcode); /*NOTREACHED*/ } ... if (help) usa...
2
2009-11-04T11:02:48Z
[ "python", "trivia" ]
Why does python -V write to the error stream?
1,672,650
<p>I was writing a script to inspect python's version on my system and I've noticed that <code>python -V</code> writes to the error stream, while <code>python -h</code>, for instance, uses the standard output. Is there a good reason for this behavior?</p>
6
2009-11-04T09:34:36Z
1,673,101
<p>Probably for no good reason, some digging revealed the <a href="http://svn.python.org/view/python/trunk/Modules/main.c?view=diff&amp;r1=17457&amp;r2=17458" rel="nofollow">the patch</a> adding the options, but I can find any references to why the different streams are used in the discussion about the patch.</p>
1
2009-11-04T11:06:04Z
[ "python", "trivia" ]
Why does python -V write to the error stream?
1,672,650
<p>I was writing a script to inspect python's version on my system and I've noticed that <code>python -V</code> writes to the error stream, while <code>python -h</code>, for instance, uses the standard output. Is there a good reason for this behavior?</p>
6
2009-11-04T09:34:36Z
1,673,210
<p>Why?</p> <p>Because it's not the actual output of your actual script.</p> <p>That's the long-standing, standard, common, typical, ordinary use for standard error: everything NOT output from your script.</p>
2
2009-11-04T11:28:21Z
[ "python", "trivia" ]
Why does python -V write to the error stream?
1,672,650
<p>I was writing a script to inspect python's version on my system and I've noticed that <code>python -V</code> writes to the error stream, while <code>python -h</code>, for instance, uses the standard output. Is there a good reason for this behavior?</p>
6
2009-11-04T09:34:36Z
1,675,051
<p>The -h option also used to print to stderr because it is not part of the output of your program, i.e. the output is not produced by your Python script but by the Python interpreter itself. </p> <p>As for why they changed the -h to use stdout? Try typing <code>python -h</code> with your terminal window set to the st...
3
2009-11-04T16:38:31Z
[ "python", "trivia" ]