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
How to implement full text search in Django?
2,461,322
<p>I would like to implement a search function in a django blogging application. The status quo is that I have a list of strings supplied by the user and the queryset is narrowed down by each string to include only those objects that match the string. </p> <p>See:</p> <pre><code>if request.method == "POST": form ...
8
2010-03-17T10:09:44Z
2,461,450
<p>For full text search in Python, look at <a href="http://lucene.apache.org/pylucene/" rel="nofollow">PyLucene</a>. It allows for very complex queries. The main problem here is that you must find a way to tell your search engine which pages changed and update the index eventually.</p> <p>Alternatively, you can use <a...
2
2010-03-17T10:29:53Z
[ "python", "django", "django-queryset", "full-text-search" ]
How to implement full text search in Django?
2,461,322
<p>I would like to implement a search function in a django blogging application. The status quo is that I have a list of strings supplied by the user and the queryset is narrowed down by each string to include only those objects that match the string. </p> <p>See:</p> <pre><code>if request.method == "POST": form ...
8
2010-03-17T10:09:44Z
2,461,461
<p>Actually, the query you have posted <em>does</em> use OR rather than AND - you're using <code>\</code> to separate the <code>Q</code> objects. AND would be <code>&amp;</code>.</p> <p>In general, I would highly recommend using a proper search engine. We have had good success with Haystack on top of Solr - Haystack m...
4
2010-03-17T10:31:57Z
[ "python", "django", "django-queryset", "full-text-search" ]
How to implement full text search in Django?
2,461,322
<p>I would like to implement a search function in a django blogging application. The status quo is that I have a list of strings supplied by the user and the queryset is narrowed down by each string to include only those objects that match the string. </p> <p>See:</p> <pre><code>if request.method == "POST": form ...
8
2010-03-17T10:09:44Z
2,461,498
<p>Answer to your <em>general</em> question: Definitely use a proper application for this.</p> <p>With your query, you <strong>always examine the whole content</strong> of the fields (title, text, tags). You gain no benefit from indexes, etc.</p> <p>With a proper full text search engine (or whatever you call it), <st...
4
2010-03-17T10:37:00Z
[ "python", "django", "django-queryset", "full-text-search" ]
How to implement full text search in Django?
2,461,322
<p>I would like to implement a search function in a django blogging application. The status quo is that I have a list of strings supplied by the user and the queryset is narrowed down by each string to include only those objects that match the string. </p> <p>See:</p> <pre><code>if request.method == "POST": form ...
8
2010-03-17T10:09:44Z
2,461,501
<p>I suggest you to adopt a search engine.</p> <p>We've used <a href="http://haystacksearch.org/">Haystack search</a>, a modular search application for django supporting many search engines (Solr, Xapian, Whoosh, etc...)</p> <p>Advantages:</p> <ul> <li>Faster</li> <li>perform search queries even without querying the...
15
2010-03-17T10:37:21Z
[ "python", "django", "django-queryset", "full-text-search" ]
How to implement full text search in Django?
2,461,322
<p>I would like to implement a search function in a django blogging application. The status quo is that I have a list of strings supplied by the user and the queryset is narrowed down by each string to include only those objects that match the string. </p> <p>See:</p> <pre><code>if request.method == "POST": form ...
8
2010-03-17T10:09:44Z
2,461,662
<p>SOLR is very easy to setup and integrate with Django. Haystack makes it even simpler.</p>
4
2010-03-17T11:05:52Z
[ "python", "django", "django-queryset", "full-text-search" ]
How to implement full text search in Django?
2,461,322
<p>I would like to implement a search function in a django blogging application. The status quo is that I have a list of strings supplied by the user and the queryset is narrowed down by each string to include only those objects that match the string. </p> <p>See:</p> <pre><code>if request.method == "POST": form ...
8
2010-03-17T10:09:44Z
2,462,751
<p>I think full text search on an application level is more a matter of what you have and how you expect it to scale. If you run a small site with low usage I think it might be more affordable to put some time into making an custom full text search rather than installing an application to perform the search for you. An...
2
2010-03-17T13:57:53Z
[ "python", "django", "django-queryset", "full-text-search" ]
django: search forms and redirect
2,461,364
<p>After processing form from POST I should redirect, to prevent user from hitting back. However, I am using form to determine search query on a database, so I need to either pass params to the redirected site or the result of a search. Or maybe there is some other good practice, how to solve this problem? Maybe in thi...
0
2010-03-17T10:15:55Z
2,461,426
<p>Search queries should probably be GETs, rather than POSTs, because they are not changing anything - they are simply passing parameters to get certain information. POST should be reserved for forms that actually change things in the database, or result in a specific action (eg submitting an email).</p> <p>To reply t...
3
2010-03-17T10:25:40Z
[ "python", "django", "redirect", "search-form" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
2,461,861
<p>In my opinion, things like dependency injection are symptoms of a rigid and over-complex framework. When the main body of code becomes much too weighty to change easily, you find yourself having to pick small parts of it, define interfaces for them, and then allowing people to change behaviour via the objects that p...
5
2010-03-17T11:41:20Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
2,462,042
<p>Haven't used Python in several years, but I would say that it has more to do with it being a dynamically typed language than anything else. For a simple example, in Java, if I wanted to test that something wrote to standard out appropriately I could use DI and pass in any PrintStream to capture the text being writte...
8
2010-03-17T12:10:16Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
2,462,076
<p>Part of it is the way the module system works in Python. You can get a sort of "singleton" for free, just by importing it from a module. Define an actual instance of an object in a module, and then any client code can import it and actually get a working, fully constructed / populated object.</p> <p>This is in co...
24
2010-03-17T12:16:25Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
2,465,052
<p>I don't actually think that DI/IoC are <em>that</em> uncommon in Python. What <em>is</em> uncommon, however, are DI/IoC <em>frameworks/containers</em>.</p> <p>Think about it: what does a DI container do? It allows you to </p> <ol> <li>wire together independent components into a complete application ...</li> <li>.....
113
2010-03-17T18:59:17Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
2,465,344
<p>Django makes great use of inversion of control. For instance, the database server is selected by the configuration file, then the framework provides appropriate database wrapper instances to database clients.</p> <p>The difference is that Python has first-class types. Data types, including classes, are themselves...
30
2010-03-17T19:46:56Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
2,472,529
<p>Actually, it is quite easy to write sufficiently clean and compact code with DI (I wonder, will it be/stay <em>pythonic</em> then, but anyway :) ), for example I actually perefer this way of coding:</p> <pre><code>def polite(name_str): return "dear " + name_str def rude(name_str): return name_str + ", you,...
5
2010-03-18T18:52:27Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
6,502,457
<p>I use IoC with Ruby, here's my thoughts about why it's not widely spread</p> <p><a href="http://ruby-lang.info/blog/you-underestimate-the-power-of-ioc-3fh" rel="nofollow">http://ruby-lang.info/blog/you-underestimate-the-power-of-ioc-3fh</a></p> <p>UPDATE:</p> <p>I don't support that site anymore, link doesn't wor...
1
2011-06-28T06:29:11Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
7,308,688
<p>I back "Jörg W Mittag" answer: "The Python implementation of DI/IoC is so lightweight that it completely vanishes".</p> <p>To back up this statement, take a look at the famous Martin Fowler's example ported from Java to Python: <a href="https://web.archive.org/web/20130703221553/http://www.emilmont.net/doku.php?id...
12
2011-09-05T13:19:24Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
10,252,523
<p>I agree with @Jorg in the point that DI/IoC is possible, easier and even more beautiful in Python. What's missing is the frameworks supporting it, but there are a few exceptions. To point a couple of examples that come to my mind:</p> <ul> <li><p>Django comments let you wire your own Comment class with your custom ...
-1
2012-04-20T19:39:36Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
27,632,254
<p>IoC/DI is a design concept, but unfortunately it's often taken as a concept that applies to certain languages (or typing systems). I'd love to see dependency injection containers become far more popular in Python. There's Spring, but that's a super-framework and seems to be a direct port of the Java concepts without...
1
2014-12-24T06:03:24Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
32,825,348
<p>I think due to the dynamic nature of python people don't often see the need for another dynamic framework. When a class inherits from the new-style 'object' you can create a new variable dynamically (<a href="https://wiki.python.org/moin/NewClassVsClassicClass" rel="nofollow">https://wiki.python.org/moin/NewClassVs...
-1
2015-09-28T14:19:51Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Why is IoC / DI not common in Python?
2,461,702
<p>In Java <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> / <a href="http://en.wikipedia.org/wiki/Dependency_Injection">DI</a> is a very common practice which is extensively used in web applications, nearly all available frameworks and Java EE. On the other hand, there are also lots of big Python w...
146
2010-03-17T11:10:33Z
39,896,946
<p>Unlike the strong typed nature in Java. Python's duck typing behavior makes it so easy to pass objects around. </p> <p>Java developers are focusing on the constructing the class strcuture and relation between objects, while keeping things flexible. IoC is extremely important for achieving this.</p> <p>Python de...
0
2016-10-06T13:10:24Z
[ "python", "design-patterns", "dependency-injection", "inversion-of-control", "architecture" ]
Python: Class factory using user input as class names
2,461,751
<p>I want to add class atttributes to a superclass dynamically. Furthermore, I want to create classes that inherit from this superclass dynamically, and the name of those subclasses should depend on user input.</p> <p>There is a superclass "Unit", to which I can add attributes at runtime. This already works. </p> <p...
10
2010-03-17T11:20:31Z
2,461,882
<p>Have a look at the <a href="http://docs.python.org/library/functions.html"><code>type()</code></a> builtin function.</p> <pre><code>knight_class = type('Knight', (Unit,), {}) </code></pre> <ul> <li>First parameter: Name of new class</li> <li>Second parameter: Tuple of parent classes</li> <li>Third parameter: dicti...
6
2010-03-17T11:46:28Z
[ "python", "metaprogramming", "factory", "metaclass" ]
Python: Class factory using user input as class names
2,461,751
<p>I want to add class atttributes to a superclass dynamically. Furthermore, I want to create classes that inherit from this superclass dynamically, and the name of those subclasses should depend on user input.</p> <p>There is a superclass "Unit", to which I can add attributes at runtime. This already works. </p> <p...
10
2010-03-17T11:20:31Z
2,461,898
<p>To create a class from a name, use the <code>class</code> statement and assign the name. Observe:</p> <pre><code>def meta(name): class cls(Unit): pass cls.__name__ = name return cls </code></pre> <p>Now I suppose I should explain myself, and so on. When you create a class using the class state...
13
2010-03-17T11:49:08Z
[ "python", "metaprogramming", "factory", "metaclass" ]
How to parse the "<media:group>" using feedparser?
2,461,853
<p>The rss file is shown as below, i want to get the content in section <strong>media:group</strong> . I check the document of feedparser, but it seems not mention this. How to do it? Any help is appreciated. </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;rss xmlns:ymusic="http://music.yahoo.com/rss...
3
2010-03-17T11:39:56Z
2,462,326
<p>You can parse the feed using </p> <pre><code>feed = feedparser.parse(your_feeds_url) </code></pre> <p>and then access your xml elements using either python's attribute access or dictionary-like access on <code>feed</code> and its subelements. The former method won't work for an element name like <code>media:conten...
0
2010-03-17T12:59:28Z
[ "python", "rss", "feedparser" ]
How to parse the "<media:group>" using feedparser?
2,461,853
<p>The rss file is shown as below, i want to get the content in section <strong>media:group</strong> . I check the document of feedparser, but it seems not mention this. How to do it? Any help is appreciated. </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;rss xmlns:ymusic="http://music.yahoo.com/rss...
3
2010-03-17T11:39:56Z
3,150,461
<p>feedparser 4.1 as available from PyPi has this bug.</p> <p>the solution for me was to get the latest feedparser.py (4.2 pre) from the repository.</p> <pre><code>svn checkout http://feedparser.googlecode.com/svn/trunk/ feedparser-readonly cd feedparser-readonly python setup.py install </code></pre> <p>now you can ...
3
2010-06-30T14:57:25Z
[ "python", "rss", "feedparser" ]
Python: circular imports needed for type checking
2,461,907
<p>First of all: I do know that there are already many questions and answers to the topic of the circular imports. </p> <p>The answer is more or less: "Design your Module/Class structure properly and you will not need circular imports". That is true. I tried very hard to make a proper design for my current project, I ...
6
2010-03-17T11:50:44Z
2,461,961
<p>The best solution is to not check types. </p> <p>The other solution is to not create an instance of, and not reference at all, <code>Foo</code> or <code>Bar</code> until both classes are loaded. If the first module is loaded first, don't create a <code>Bar</code> or refer to <code>Bar</code> until after the <code>c...
4
2010-03-17T11:59:05Z
[ "python", "import", "circular-dependency" ]
Python: circular imports needed for type checking
2,461,907
<p>First of all: I do know that there are already many questions and answers to the topic of the circular imports. </p> <p>The answer is more or less: "Design your Module/Class structure properly and you will not need circular imports". That is true. I tried very hard to make a proper design for my current project, I ...
6
2010-03-17T11:50:44Z
2,461,968
<p>You could just defer the import in bar.py like this:</p> <pre><code>class Bar(object): def __init__(self, arg_instance_of_foo): from foo import Foo if not isinstance(arg_instance_of_foo, Foo): raise TypeError() </code></pre>
1
2010-03-17T11:59:47Z
[ "python", "import", "circular-dependency" ]
Python: circular imports needed for type checking
2,461,907
<p>First of all: I do know that there are already many questions and answers to the topic of the circular imports. </p> <p>The answer is more or less: "Design your Module/Class structure properly and you will not need circular imports". That is true. I tried very hard to make a proper design for my current project, I ...
6
2010-03-17T11:50:44Z
2,462,040
<p>You can program against <code>interface</code> (ABC - <a href="http://docs.python.org/library/abc.html" rel="nofollow">abstract base class</a> in python), and not specific type <code>Bar</code>. This is classical way to resolve package/module inter-dependencies in many languages. Conceptually it should also result i...
3
2010-03-17T12:10:08Z
[ "python", "import", "circular-dependency" ]
Running a python script in background from a CGI
2,461,964
<p>I have a python CGI which runs some script in the background and shows the stdout in the html page. I run the script when the user clicks some button in the page.</p> <p>My problem is when the script starts running the page becomes busy and the user can't use the other client side features in the page.</p> <p>What...
1
2010-03-17T11:59:28Z
2,462,349
<p>well, short answer: you can't.</p> <p>medium answer: CGI sucks.</p> <p>long answer: CGI works by running your script and returning whatever your script prints to the browser. If your script is still running, the browser will be waiting. If your script launches a background job and returns data to the browser, then...
2
2010-03-17T13:03:48Z
[ "python", "cgi", "backgroundworker" ]
How do I create self-relationships in polymorphic inheritance in Elixir and Pylons?
2,462,049
<p>I am new to programming and am following the example in the Pylons documentation on creating a Wiki. The database I want to link to the wiki was created with Elixir so I rewrote the Wiki database schema and have continued from there.</p> <p>In the wiki there is a <a href="http://pylonsbook.com/en/1.1/simplesite-tut...
0
2010-03-17T12:10:49Z
2,473,324
<p>I think that your model is mostly correct. The only thing I found is the link <code>section</code> from Nav->Page and back:</p> <pre><code>class Nav(Entity): section = OneToMany('Page', inverse='section') class Page(Nav): section = ManyToOne('Nav', inverse='section') </code></pre> <p>The tutorial just that...
0
2010-03-18T21:02:16Z
[ "python", "sqlalchemy", "pylons", "python-elixir" ]
Logical python question - handling directories and files in them
2,462,078
<p>I'm using this function to extract files from .zip archive and store it on the server:</p> <pre><code>def unzip_file_into_dir(file, dir): import sys, zipfile, os, os.path os.makedirs(dir, 0777) zfobj = zipfile.ZipFile(file) for name in zfobj.namelist(): if name.endswith('/'): os...
0
2010-03-17T12:17:16Z
2,462,132
<p>Use</p> <pre><code>outfile = open(os.path.join(dir, os.path.basename(name)), 'wb') </code></pre> <p>to strip the path from the name of the ZIP entry. This way, only the filename is left and you don't get any directories. You must also comment out the <code>os.mkdir()</code> or replace it with <code>pass</code>.</p...
4
2010-03-17T12:25:43Z
[ "python" ]
error :: UnicodeDecodeError
2,462,166
<p>I am getting </p> <pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 104: ordinal not in range(128) </code></pre> <p>I am using <code>intgereproparty</code>, <code>stringproparty</code>, <code>datetimeproparty</code></p>
1
2010-03-17T12:31:23Z
2,462,189
<p>That's because <code>0xb0</code> (decimal 176) is not a valid character code in ASCII (which defines only values between 0 and 127).</p> <p>Check where you got that string from and use the proper encoding.</p> <p>If you need further help, post the code.</p>
1
2010-03-17T12:35:08Z
[ "python" ]
error :: UnicodeDecodeError
2,462,166
<p>I am getting </p> <pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 104: ordinal not in range(128) </code></pre> <p>I am using <code>intgereproparty</code>, <code>stringproparty</code>, <code>datetimeproparty</code></p>
1
2010-03-17T12:31:23Z
2,462,202
<p>You are trying to put Unicode data (probably text with accents) into an ASCII string.</p> <p>You can use Python's codecs module to open a text file with UTF-8 encoding and write the Unicode data to it.</p> <p>The <code>.encode</code> method may also help (<code>u"õ".encode('utf-8')</code> for example)</p>
1
2010-03-17T12:38:05Z
[ "python" ]
error :: UnicodeDecodeError
2,462,166
<p>I am getting </p> <pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 104: ordinal not in range(128) </code></pre> <p>I am using <code>intgereproparty</code>, <code>stringproparty</code>, <code>datetimeproparty</code></p>
1
2010-03-17T12:31:23Z
2,462,337
<p>Python defaults to ASCII encoding - if you are dealing with chars outside of the ASCII range, you need to specify that in your code.</p> <p>One way to do this is setting the defining the encoding at the top of your code. </p> <p>This snippet sets the encoding at the top of the file to encoding to Latin-1 (which in...
0
2010-03-17T13:02:09Z
[ "python" ]
error :: UnicodeDecodeError
2,462,166
<p>I am getting </p> <pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 104: ordinal not in range(128) </code></pre> <p>I am using <code>intgereproparty</code>, <code>stringproparty</code>, <code>datetimeproparty</code></p>
1
2010-03-17T12:31:23Z
7,519,131
<p>When I write my foreign language "flashcard" programs, I always use python 3.x as its native encoding is utf-8. You're encoding problems will generally be far less frequent.</p> <p>If you're working on a program that many people will share, however, you may want to consider using <code>encode</code> and <code>decod...
0
2011-09-22T17:44:37Z
[ "python" ]
How do I create a python module from a fortran program with f2py?
2,462,354
<p>I am trying to read some smps files with python, and found a fortran implementation, so I thought I would give f2py a shot. The problem is that I have no experience with fortran.</p> <p>I have successfully installed gfortran and f2py on my Linux box and ran the example on thew f2py page, but I have some trouble com...
2
2010-03-17T13:04:12Z
2,462,701
<p>I would suggest skipping the fortran business altogether.</p> <p><a href="http://myweb.dal.ca/gassmann/smps2.htm" rel="nofollow">http://myweb.dal.ca/gassmann/smps2.htm</a></p> <p>The MPS record layout is described here, and looks relatively simple to pick apart in Python.</p> <p><a href="http://myweb.dal.ca/gassm...
0
2010-03-17T13:50:39Z
[ "python", "fortran", "f2py" ]
Problem in understanding connectSlotsByName() in pyqt?
2,462,401
<p>I couldn't understand the connectSlotsByName() method which is predominently used by pyuic4.. As far the class is single in a PyQt file it's ok since we can use self which will be associated with a single object throughout.. But when we try to use various classes from different files the problem and the need to use ...
4
2010-03-17T13:10:18Z
2,463,932
<p>You do not need to call <code>connectSlotsByName()</code>, just remove those lines.</p> <p>In <code>file2</code>, calling <code>QtCore.QMetaObject.connectSlotsByName(self.page)</code> tries to do this:</p> <pre><code>QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.on_pushButton_clicked()) ...
2
2010-03-17T16:18:37Z
[ "python", "qt", "pyqt" ]
Problem in understanding connectSlotsByName() in pyqt?
2,462,401
<p>I couldn't understand the connectSlotsByName() method which is predominently used by pyuic4.. As far the class is single in a PyQt file it's ok since we can use self which will be associated with a single object throughout.. But when we try to use various classes from different files the problem and the need to use ...
4
2010-03-17T13:10:18Z
2,490,360
<p>Thank you so much jcoon for your reply.. But after a very long time banging my head against the wall i found the solution..</p> <p>The problem was..</p> <pre><code>self.obj=test_reuse_stacked1.widget2() self.obj.createWidget2(self) </code></pre> <p>instead of obj.. </p>
0
2010-03-22T06:31:04Z
[ "python", "qt", "pyqt" ]
Problem in understanding connectSlotsByName() in pyqt?
2,462,401
<p>I couldn't understand the connectSlotsByName() method which is predominently used by pyuic4.. As far the class is single in a PyQt file it's ok since we can use self which will be associated with a single object throughout.. But when we try to use various classes from different files the problem and the need to use ...
4
2010-03-17T13:10:18Z
2,500,375
<p>At first, here is the minimal working example:</p> <pre><code>from sys import argv, exit from PyQt4 import QtCore, QtGui class widget2(QtGui.QWidget): def __init__(self, args): self.app = MainApp(args) QtGui.QWidget.__init__(self) self.setObjectName('I') self._layout = QtGui.Q...
2
2010-03-23T13:50:32Z
[ "python", "qt", "pyqt" ]
Problem in understanding connectSlotsByName() in pyqt?
2,462,401
<p>I couldn't understand the connectSlotsByName() method which is predominently used by pyuic4.. As far the class is single in a PyQt file it's ok since we can use self which will be associated with a single object throughout.. But when we try to use various classes from different files the problem and the need to use ...
4
2010-03-17T13:10:18Z
2,595,656
<p>A better question is "Why not just use new-style signals and slots?". They're much simpler and don't require any weird naming conventions:</p> <pre><code>from sys import argv, exit from PyQt4 import QtCore, QtGui class MyWidget(QtGui.QWidget): def __init__(self, parent=None): super(MyWidget, self).__in...
2
2010-04-07T20:24:51Z
[ "python", "qt", "pyqt" ]
Python: 'break' outside loop
2,462,566
<p>in the following python code:</p> <pre><code>narg=len(sys.argv) print "@length arg= ", narg if narg == 1: print "@Usage: input_filename nelements nintervals" break </code></pre> <p>I get:</p> <pre><code>SyntaxError: 'break' outside loop </code></pre> <p>Why?</p>
7
2010-03-17T13:32:45Z
2,462,583
<p>Because break cannot be used to break out of an if - it can only break out of loops. That's the way Python (and most other languages) are specified to behave.</p> <p>What are you trying to do? Perhaps you should use <code>sys.exit()</code> or <code>return</code> instead?</p>
26
2010-03-17T13:34:50Z
[ "python" ]
Python: 'break' outside loop
2,462,566
<p>in the following python code:</p> <pre><code>narg=len(sys.argv) print "@length arg= ", narg if narg == 1: print "@Usage: input_filename nelements nintervals" break </code></pre> <p>I get:</p> <pre><code>SyntaxError: 'break' outside loop </code></pre> <p>Why?</p>
7
2010-03-17T13:32:45Z
2,462,586
<p>Because the break statement is intended to break out of loops. You don't need to break out of an if statement - it just ends at the end.</p>
2
2010-03-17T13:35:14Z
[ "python" ]
Python: 'break' outside loop
2,462,566
<p>in the following python code:</p> <pre><code>narg=len(sys.argv) print "@length arg= ", narg if narg == 1: print "@Usage: input_filename nelements nintervals" break </code></pre> <p>I get:</p> <pre><code>SyntaxError: 'break' outside loop </code></pre> <p>Why?</p>
7
2010-03-17T13:32:45Z
2,462,590
<p>Because break can only be used inside a loop. It is used to break out of a loop (stop the loop).</p>
2
2010-03-17T13:35:29Z
[ "python" ]
Python: 'break' outside loop
2,462,566
<p>in the following python code:</p> <pre><code>narg=len(sys.argv) print "@length arg= ", narg if narg == 1: print "@Usage: input_filename nelements nintervals" break </code></pre> <p>I get:</p> <pre><code>SyntaxError: 'break' outside loop </code></pre> <p>Why?</p>
7
2010-03-17T13:32:45Z
2,463,920
<p><code>break</code> breaks out of a loop, not an <code>if</code> statement, as others have pointed out. The motivation for this isn't too hard to see; think about code like</p> <pre><code>for item in some_iterable: ... if break_condition(): break </code></pre> <p>The <code>break</code> would be pre...
0
2010-03-17T16:17:27Z
[ "python" ]
Discovery of web services using Python
2,462,618
<p>I have several devices on a network. I am trying to use a library to discover the presence and itentity of these devices using Python script, the devices all have a web service. My question is, are there any modules that would help me with this problem as the only module I have found is ws-discovery for Python? </p>...
1
2010-03-17T13:39:31Z
2,487,240
<p>Unfortunately I've never used ws-discovery myself, but there seems to be a Python project which implements it: <a href="http://code.google.com/p/python-ws-discovery/" rel="nofollow">http://code.google.com/p/python-ws-discovery/</a></p> <p>From their documentation here's a short example on how to use it:</p> <pre><...
0
2010-03-21T13:33:29Z
[ "python", "web-services", "ws-discovery" ]
Discovery of web services using Python
2,462,618
<p>I have several devices on a network. I am trying to use a library to discover the presence and itentity of these devices using Python script, the devices all have a web service. My question is, are there any modules that would help me with this problem as the only module I have found is ws-discovery for Python? </p>...
1
2010-03-17T13:39:31Z
2,513,638
<p>Are you tied to ws-discovery? If not, you might want to consider the Bonjour protocol, aka ZeroConf and DNS-SD. The protocol is relatively widely implemented. I've never used python to do the advertising or discovery but there is a project that implements an API: <a href="http://code.google.com/p/pybonjour/" rel=...
1
2010-03-25T07:06:22Z
[ "python", "web-services", "ws-discovery" ]
cv.SaveImage in openCV
2,462,725
<p>I'm trying to learn how to use opencv in python and having some difficulties, and also I'm a newbie at python too.</p> <p>Here is my question :</p> <p>I want to convert a jpg file tp png. Simple and clear. But when I run this code :</p> <pre><code>from opencv import _cv from opencv.highgui import cvSaveImage, cv...
2
2010-03-17T13:55:35Z
2,465,838
<p>I solved the problem, the image I took randomly from the Google Images doesn't load. Maybe it's encrypted or something I don't know. I tried it with other images, and worked very well. So watch out while copying images : ) </p>
1
2010-03-17T20:55:59Z
[ "python", "opencv" ]
cv.SaveImage in openCV
2,462,725
<p>I'm trying to learn how to use opencv in python and having some difficulties, and also I'm a newbie at python too.</p> <p>Here is my question :</p> <p>I want to convert a jpg file tp png. Simple and clear. But when I run this code :</p> <pre><code>from opencv import _cv from opencv.highgui import cvSaveImage, cv...
2
2010-03-17T13:55:35Z
5,216,140
<p>The best choice is pyopencv:</p> <pre><code>import pyopencv as cv img = cv.imread('01.png') cv.imshow('img-windows',img) cv.waitKey(0) cv.imwrite('01.png',img) </code></pre>
4
2011-03-07T05:23:01Z
[ "python", "opencv" ]
cv.SaveImage in openCV
2,462,725
<p>I'm trying to learn how to use opencv in python and having some difficulties, and also I'm a newbie at python too.</p> <p>Here is my question :</p> <p>I want to convert a jpg file tp png. Simple and clear. But when I run this code :</p> <pre><code>from opencv import _cv from opencv.highgui import cvSaveImage, cv...
2
2010-03-17T13:55:35Z
29,108,426
<p>From <a href="http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html" rel="nofollow">Python CV documentation</a>, the CV2 method for converting a jpeg to png is: <code>Python: cv2.imwrite(filename, img[, params]) → retval</code></p> <p>For my example: `</p> <pre><code>import cv...
1
2015-03-17T19:51:36Z
[ "python", "opencv" ]
how to set wxPython main frame bottom right on screen?
2,462,802
<p>For better description,</p> <pre><code>+-----------------------+ | Desktop (screen) | | | | | | +----------+ | | | wxPython | | | | App. | | | | | | | | | | | +----------+ | +----------------...
6
2010-03-17T14:03:47Z
2,463,774
<p>You can use wx.DisplaySize to get display screen size, and from window.GetSize() you can get the size of your window which you want to position, these two informations are enough to pos it correctly. e.g. in this example I position a MinFrame it at bottom-right</p> <pre><code>import wx def alignToBottomRight(win):...
10
2010-03-17T15:57:47Z
[ "python", "wxpython" ]
Is it possible to change the model name in the django admin site?
2,462,905
<p>I am translating a django app and I would like to translate also the homepage of the django admin site. </p> <p>On this page are listed the application names and the model class names. I would like to translate the model class name but I don't find how to give a user-friendly name for a model class.</p> <p>Does an...
25
2010-03-17T14:15:42Z
2,462,921
<p>Look at the <a href="https://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name"><code>Meta</code> options</a> <code>verbose_name</code> and <code>verbose_name_plural</code>, both of which are translatable.</p>
42
2010-03-17T14:17:32Z
[ "python", "django", "django-models", "django-admin" ]
I want to select the distinct value from models field and then update them (django)
2,462,962
<p>I have models...</p> <pre><code>class Item(models.Model): name = models.CharField('Item Name', max_length = 30) item_code = models.CharField(max_length = 10) color = models.CharField(max_length = 150, null = True, blank = True) size = models.CharField(max_length = 30, null = True, blank = True) ...
0
2010-03-17T14:21:47Z
2,463,085
<p>I don't really understand your question. Do you want to select distinct values for name, as in</p> <pre><code>Item.objects.values('name').distinct() </code></pre>
0
2010-03-17T14:36:46Z
[ "python", "django", "django-models" ]
I want to select the distinct value from models field and then update them (django)
2,462,962
<p>I have models...</p> <pre><code>class Item(models.Model): name = models.CharField('Item Name', max_length = 30) item_code = models.CharField(max_length = 10) color = models.CharField(max_length = 150, null = True, blank = True) size = models.CharField(max_length = 30, null = True, blank = True) ...
0
2010-03-17T14:21:47Z
2,468,674
<p>if you want to change a widget choices items, use something like this :</p> <pre><code>choices_list = Item.objects.values_list('name','name').distinct() form_item = forms.ModelChoiceField(label = 'Select Item', choices = choices_list) </code></pre> <p>As said in the <a href="http://docs.djangoproject.com/en/dev/re...
0
2010-03-18T09:31:24Z
[ "python", "django", "django-models" ]
Python: using a regular expression to match one line of HTML
2,463,188
<p>This simple Python method I put together just checks to see if Tomcat is running on one of our servers.</p> <pre><code>import urllib2 import re import sys def tomcat_check(): tomcat_status = urllib2.urlopen('http://10.1.1.20:7880') results = tomcat_status.read() pattern = re.compile('&lt;body&gt;Tomca...
1
2010-03-17T14:48:25Z
2,463,217
<p>Why use regex here at all? Why not just a simple string search?:</p> <pre><code>if not '&lt;body&gt;Tomcat is running...&lt;/body&gt;' in results: notify_us() </code></pre>
8
2010-03-17T14:52:19Z
[ "python", "html", "regex" ]
Python: using a regular expression to match one line of HTML
2,463,188
<p>This simple Python method I put together just checks to see if Tomcat is running on one of our servers.</p> <pre><code>import urllib2 import re import sys def tomcat_check(): tomcat_status = urllib2.urlopen('http://10.1.1.20:7880') results = tomcat_status.read() pattern = re.compile('&lt;body&gt;Tomca...
1
2010-03-17T14:48:25Z
2,463,247
<p>Since you appear to be looking for a fixed string (not a regexp) that you have some control over and can be expected to be consistent, <a href="http://docs.python.org/library/stdtypes.html#string-methods" rel="nofollow">str.find()</a> should do just fine. Or what Daniel said.</p>
0
2010-03-17T14:55:28Z
[ "python", "html", "regex" ]
Python: using a regular expression to match one line of HTML
2,463,188
<p>This simple Python method I put together just checks to see if Tomcat is running on one of our servers.</p> <pre><code>import urllib2 import re import sys def tomcat_check(): tomcat_status = urllib2.urlopen('http://10.1.1.20:7880') results = tomcat_status.read() pattern = re.compile('&lt;body&gt;Tomca...
1
2010-03-17T14:48:25Z
2,463,253
<pre><code>if not 'Tomcat is running' in results: notify_us() </code></pre>
2
2010-03-17T14:56:28Z
[ "python", "html", "regex" ]
Python: using a regular expression to match one line of HTML
2,463,188
<p>This simple Python method I put together just checks to see if Tomcat is running on one of our servers.</p> <pre><code>import urllib2 import re import sys def tomcat_check(): tomcat_status = urllib2.urlopen('http://10.1.1.20:7880') results = tomcat_status.read() pattern = re.compile('&lt;body&gt;Tomca...
1
2010-03-17T14:48:25Z
2,463,284
<p>As you have mentioned, regular expressions aren't suited for parsing XML like structures (at least, for more complex queries). I would do something like that:</p> <pre><code>from lxml import etree import urllib2 def tomcat_check(host='127.0.0.1', port=7880): response = urllib2.urlopen('http://%s:%d' % (host, p...
0
2010-03-17T14:59:45Z
[ "python", "html", "regex" ]
Python: using a regular expression to match one line of HTML
2,463,188
<p>This simple Python method I put together just checks to see if Tomcat is running on one of our servers.</p> <pre><code>import urllib2 import re import sys def tomcat_check(): tomcat_status = urllib2.urlopen('http://10.1.1.20:7880') results = tomcat_status.read() pattern = re.compile('&lt;body&gt;Tomca...
1
2010-03-17T14:48:25Z
2,463,315
<p>There are lots of different methods:</p> <h2><a href="http://codepad.org/F2LU1piS" rel="nofollow">str.find()</a></h2> <pre><code>if results.find("Tomcat is running...") != -1: print "Tomcat appears to be running" else: notify_us() </code></pre> <h2><a href="http://codepad.org/PuOrXuGY" rel="nofollow">Usin...
1
2010-03-17T15:03:04Z
[ "python", "html", "regex" ]
Get the dictionary values for every key in a list
2,463,196
<p>Let's say I have a list:</p> <pre><code>a = ['apple', 'carrot'] </code></pre> <p>and a dictionary:</p> <pre><code>d ={'apple': [2,4], 'carrot': [44,33], 'orange': [345,667]} </code></pre> <p>How can I use the list <strong>a</strong> as a key to lookup in the dictionary <strong>d</strong>? I want the result to be...
5
2010-03-17T14:49:52Z
2,463,297
<pre><code>a = ['apple', 'orange'] d ={'apple': [2,4], 'carrot': [44,33], 'orange': [345,667]} print ',\t'.join(a) for row in zip(*(d[key] for key in a)): print ',\t'.join(map(str, row)) </code></pre> <p>Output:</p> <pre><code>apple, orange 2, 345 4, 667 </code></pre>
8
2010-03-17T15:01:29Z
[ "python", "dictionary" ]
Get the dictionary values for every key in a list
2,463,196
<p>Let's say I have a list:</p> <pre><code>a = ['apple', 'carrot'] </code></pre> <p>and a dictionary:</p> <pre><code>d ={'apple': [2,4], 'carrot': [44,33], 'orange': [345,667]} </code></pre> <p>How can I use the list <strong>a</strong> as a key to lookup in the dictionary <strong>d</strong>? I want the result to be...
5
2010-03-17T14:49:52Z
2,463,397
<p>I know other people have been faster and their solutions are similar, but here's my take (take it or leave it):</p> <pre><code>a = ['apple', 'orange'] d ={'apple': [2,4], 'carrot': [44,33], 'orange': [345,667]} fo = open('test.csv','w') fo.write(',\t'.join(a)+'\n') for y in xrange(len(d[a[0]])): fo.write(',\t...
3
2010-03-17T15:11:54Z
[ "python", "dictionary" ]
Get the dictionary values for every key in a list
2,463,196
<p>Let's say I have a list:</p> <pre><code>a = ['apple', 'carrot'] </code></pre> <p>and a dictionary:</p> <pre><code>d ={'apple': [2,4], 'carrot': [44,33], 'orange': [345,667]} </code></pre> <p>How can I use the list <strong>a</strong> as a key to lookup in the dictionary <strong>d</strong>? I want the result to be...
5
2010-03-17T14:49:52Z
13,507,346
<p>Question is very old, but for future visitors I'd suggest using <a href="http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a> to get values of dict <strong>d</strong> for keys <strong>k</strong> in list <strong>a</strong>:</p> <pre><code>values = [ d[k] f...
1
2012-11-22T06:59:32Z
[ "python", "dictionary" ]
Is it possible to renice a subprocess?
2,463,533
<p>I know about <a href="https://docs.python.org/2/library/os.html#os.nice" rel="nofollow"><code>os.nice()</code></a> it works perfect for parent process, but I need to do renice of my child subprocesses. I found way to do this, but it seems to be not very handy and too excessive:</p> <pre><code>os.system("renice -n %...
7
2010-03-17T15:26:45Z
2,463,615
<p>You should use <code>subprocess.Popen</code> instead of <code>os.system</code>, so you can access any results printed to sys.stdout. IIRC, <code>os.system</code> only gives you access to the return value, which is probably '0' and not the nice level.</p>
2
2010-03-17T15:37:02Z
[ "python", "subprocess", "nice", "renice" ]
Is it possible to renice a subprocess?
2,463,533
<p>I know about <a href="https://docs.python.org/2/library/os.html#os.nice" rel="nofollow"><code>os.nice()</code></a> it works perfect for parent process, but I need to do renice of my child subprocesses. I found way to do this, but it seems to be not very handy and too excessive:</p> <pre><code>os.system("renice -n %...
7
2010-03-17T15:26:45Z
2,463,634
<p>renice is usually implemented by set/<a href="http://www.opengroup.org/onlinepubs/000095399/functions/setpriority.html" rel="nofollow">getpriority</a> , which doesn't seem to have made it into the python os or posix module(yet?). So calling the renice system command seems like your best bet now.</p> <p>As an alter...
2
2010-03-17T15:38:39Z
[ "python", "subprocess", "nice", "renice" ]
Is it possible to renice a subprocess?
2,463,533
<p>I know about <a href="https://docs.python.org/2/library/os.html#os.nice" rel="nofollow"><code>os.nice()</code></a> it works perfect for parent process, but I need to do renice of my child subprocesses. I found way to do this, but it seems to be not very handy and too excessive:</p> <pre><code>os.system("renice -n %...
7
2010-03-17T15:26:45Z
2,464,039
<p>without proper rights you can renice only in one way</p>
1
2010-03-17T16:32:16Z
[ "python", "subprocess", "nice", "renice" ]
Is it possible to renice a subprocess?
2,463,533
<p>I know about <a href="https://docs.python.org/2/library/os.html#os.nice" rel="nofollow"><code>os.nice()</code></a> it works perfect for parent process, but I need to do renice of my child subprocesses. I found way to do this, but it seems to be not very handy and too excessive:</p> <pre><code>os.system("renice -n %...
7
2010-03-17T15:26:45Z
2,470,061
<p>Use the <code>preexec_fn</code> parameter of <a href="https://docs.python.org/2/library/subprocess.html#popen-constructor" rel="nofollow"><code>subprocess.Popen</code></a>:</p> <blockquote> <p>If <code>preexec_fn</code> is set to a callable object, this object will be called in the child process just before the c...
10
2010-03-18T13:22:10Z
[ "python", "subprocess", "nice", "renice" ]
Is it possible to renice a subprocess?
2,463,533
<p>I know about <a href="https://docs.python.org/2/library/os.html#os.nice" rel="nofollow"><code>os.nice()</code></a> it works perfect for parent process, but I need to do renice of my child subprocesses. I found way to do this, but it seems to be not very handy and too excessive:</p> <pre><code>os.system("renice -n %...
7
2010-03-17T15:26:45Z
8,165,440
<p>I created a python script with a CLI in the past. You can find it here: <a href="https://github.com/jedie/python-code-snippets/blob/master/CodeSnippets/reniceall.py" rel="nofollow">https://github.com/jedie/python-code-snippets/blob/master/CodeSnippets/reniceall.py</a></p>
0
2011-11-17T10:15:44Z
[ "python", "subprocess", "nice", "renice" ]
Simple image server
2,463,723
<p>I have a bunch of images that I need others to browse via a web browser in pretty much the same way as <a href="http://search.cpan.org/~legart/Apache-Gallery-1.0RC3/lib/Apache/Gallery.pm" rel="nofollow">Apache-Gallery</a>.</p> <p>I'd be able to dump all my images in a directory so that users hitting:</p> <p><a hre...
4
2010-03-17T15:50:55Z
2,463,831
<p>Although it doesnt use the SimpleHTTPServer class, this cgi-bin script shows how to display images in a very simply way. Extend it to fit your needs. <a href="http://lost-theory.org/python/randomimg.html" rel="nofollow">Source is here.</a></p> <pre><code>from os import listdir from random import choice ext2conttyp...
2
2010-03-17T16:04:02Z
[ "python", "http", "image" ]
Simple image server
2,463,723
<p>I have a bunch of images that I need others to browse via a web browser in pretty much the same way as <a href="http://search.cpan.org/~legart/Apache-Gallery-1.0RC3/lib/Apache/Gallery.pm" rel="nofollow">Apache-Gallery</a>.</p> <p>I'd be able to dump all my images in a directory so that users hitting:</p> <p><a hre...
4
2010-03-17T15:50:55Z
2,491,949
<p>Thanks for the answers and comments. The solution I ended up using was as per my update:</p> <ol> <li>Run <a href="http://furius.ca/curator/" rel="nofollow"><code>curator</code></a> in the directory containing all my images. This generates thumbs and an index page, as well as pagination to all the full sized images...
2
2010-03-22T11:57:08Z
[ "python", "http", "image" ]
Simple image server
2,463,723
<p>I have a bunch of images that I need others to browse via a web browser in pretty much the same way as <a href="http://search.cpan.org/~legart/Apache-Gallery-1.0RC3/lib/Apache/Gallery.pm" rel="nofollow">Apache-Gallery</a>.</p> <p>I'd be able to dump all my images in a directory so that users hitting:</p> <p><a hre...
4
2010-03-17T15:50:55Z
26,639,617
<p>This was all quite a long time ago now, but I've just begun <a href="http://www.imageme.xyz/" rel="nofollow">imageMe</a>, which aims to fulfil exactly this need. You can set it up with the instructions on the site, but if you just want to serve a basic gallery of the images in and below your current location, this c...
4
2014-10-29T20:04:33Z
[ "python", "http", "image" ]
Python in-memory zip library
2,463,770
<p>Is there a Python library that allows manipulation of zip archives in memory, without having to use actual disk files? </p> <p>The ZipFile library does not allow you to update the archive. The only way seems to be to extract it to a directory, make your changes, and create a new zip from that directory. I want to m...
24
2010-03-17T15:57:25Z
2,463,818
<p>From the article <a href="http://www.kompato.com/post/43805938842/in-memory-zip-in-python">In-Memory Zip in Python</a>:</p> <blockquote> <p>Below is a post of mine from May of 2008 on zipping in memory with Python, re-posted since Posterous is shutting down.</p> <p>I recently noticed that there is a for-pay ...
21
2010-03-17T16:02:30Z
[ "python", "memory", "zip", "archive" ]
Python in-memory zip library
2,463,770
<p>Is there a Python library that allows manipulation of zip archives in memory, without having to use actual disk files? </p> <p>The ZipFile library does not allow you to update the archive. The only way seems to be to extract it to a directory, make your changes, and create a new zip from that directory. I want to m...
24
2010-03-17T15:57:25Z
2,463,819
<p>According to the <a href="http://docs.python.org/library/zipfile.html#zipfile-objects" rel="nofollow">Python docs</a>:</p> <pre><code>class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]]) Open a ZIP file, where file can be either a path to a file (a string) or a file-like object. </code></pre> <p>So...
36
2010-03-17T16:02:39Z
[ "python", "memory", "zip", "archive" ]
Python in-memory zip library
2,463,770
<p>Is there a Python library that allows manipulation of zip archives in memory, without having to use actual disk files? </p> <p>The ZipFile library does not allow you to update the archive. The only way seems to be to extract it to a directory, make your changes, and create a new zip from that directory. I want to m...
24
2010-03-17T15:57:25Z
19,722,365
<p>The example Ethier provided has several problems, some of them major:</p> <ul> <li>doesn't work for real data on Windows. A ZIP file is binary and its data should always be written with a file opened 'wb'</li> <li>the ZIP file is appended to for each file, this is inefficient. It can just be opened and kept as an <...
13
2013-11-01T07:13:59Z
[ "python", "memory", "zip", "archive" ]
python FancyURLopener timeout
2,464,020
<p>is there a way to set connection timeout for FancyURLopener()? I'm using FancyURLopener.retrieve() to download a file, but sometimes it just stucks and that's all... I think this is because it's still trying to connect and it's not possible. So is there a way to set that timeout?</p> <p>Thanks for every reply</p>
0
2010-03-17T16:29:19Z
2,464,081
<p>Sorry, solved. I didn't realize that I could use something like this...</p> <pre><code>fileName = string.split(url, '/')[-1] data = urllib2.urlopen(url, timeout = 5) //Connection timeout set to 5 secs newF = open(os.path.join(os.getcwd(), fileName), "wb") newF.write(data.read()) newF.close() </code></p...
1
2010-03-17T16:37:12Z
[ "python", "timeout", "urllib" ]
python FancyURLopener timeout
2,464,020
<p>is there a way to set connection timeout for FancyURLopener()? I'm using FancyURLopener.retrieve() to download a file, but sometimes it just stucks and that's all... I think this is because it's still trying to connect and it's not possible. So is there a way to set that timeout?</p> <p>Thanks for every reply</p>
0
2010-03-17T16:29:19Z
2,464,124
<p>If you want to use <code>retrieve()</code> with a timeout, you can set it in the <code>socket</code> module.</p> <pre><code>import socket socket.setdefaulttimeout(5) </code></pre> <p>Source: <a href="http://docs.python.org/py3k/howto/urllib2.html#sockets-and-layers" rel="nofollow">http://docs.python.org/py3k/howto...
4
2010-03-17T16:43:55Z
[ "python", "timeout", "urllib" ]
concatenate multi values in one record without duplication
2,464,031
<p>I have a dbf table like below which is the result of one to many join from two tables. I want to have unique zone values from one Taxlot id field.</p> <p>table name: input table<br/> tid ----- zone<br/> 1 ------ A<BR/> 1 ------ A<BR/> 1 ------ B<BR/> 1 ------ C<BR/> 2 ------ D<BR/> 2 ------ E<BR/> 3 ------ C<BR/> <...
5
2010-03-17T16:31:17Z
2,464,169
<p>Here is a quickly made code in Python that may suit your needs, with minimal fidgeting.</p> <pre><code>import collections d = collections.defaultdict(list) with open("input_file.txt") as f: for line in f: parsed = line.strip().split() print parsed k = parsed[0] v = parsed[2]...
0
2010-03-17T16:51:35Z
[ "python", "vba" ]
concatenate multi values in one record without duplication
2,464,031
<p>I have a dbf table like below which is the result of one to many join from two tables. I want to have unique zone values from one Taxlot id field.</p> <p>table name: input table<br/> tid ----- zone<br/> 1 ------ A<BR/> 1 ------ A<BR/> 1 ------ B<BR/> 1 ------ C<BR/> 2 ------ D<BR/> 2 ------ E<BR/> 3 ------ C<BR/> <...
5
2010-03-17T16:31:17Z
2,467,160
<p>I think Morlock's answer does not satisfy the requirement of dropping duplicates. I would use a defaultdict(set), which will automatically omit dups, instead of defaultdict(list), and thus .add() instead of .append().</p>
1
2010-03-18T02:06:24Z
[ "python", "vba" ]
concatenate multi values in one record without duplication
2,464,031
<p>I have a dbf table like below which is the result of one to many join from two tables. I want to have unique zone values from one Taxlot id field.</p> <p>table name: input table<br/> tid ----- zone<br/> 1 ------ A<BR/> 1 ------ A<BR/> 1 ------ B<BR/> 1 ------ C<BR/> 2 ------ D<BR/> 2 ------ E<BR/> 3 ------ C<BR/> <...
5
2010-03-17T16:31:17Z
6,948,848
<p>I would use <a href="http://pypi.python.org/pypi/dbf" rel="nofollow">my dbf module</a> and <code>defaultdict</code> to greatly simplify that code:</p> <pre><code>import dbf from collections import defaltdict inputTbl = dbf.Table(r'c:\temp\input.dbf') taxIdZoning = defaultdict(set) for record in inputTbl: taxI...
3
2011-08-04T21:37:28Z
[ "python", "vba" ]
concatenate multi values in one record without duplication
2,464,031
<p>I have a dbf table like below which is the result of one to many join from two tables. I want to have unique zone values from one Taxlot id field.</p> <p>table name: input table<br/> tid ----- zone<br/> 1 ------ A<BR/> 1 ------ A<BR/> 1 ------ B<BR/> 1 ------ C<BR/> 2 ------ D<BR/> 2 ------ E<BR/> 3 ------ C<BR/> <...
5
2010-03-17T16:31:17Z
9,816,286
<p>The OP wanted commas in the zone column. Might change the output piece of Morlock's code slightly to get those commas and <em>perhaps</em> be a little clearer by using this single line for the output instead of an explicit loop over <code>v</code>:</p> <pre><code> print k, s, ",".join(v) </code></pre> <p>That ...
0
2012-03-22T04:04:29Z
[ "python", "vba" ]
concatenate multi values in one record without duplication
2,464,031
<p>I have a dbf table like below which is the result of one to many join from two tables. I want to have unique zone values from one Taxlot id field.</p> <p>table name: input table<br/> tid ----- zone<br/> 1 ------ A<BR/> 1 ------ A<BR/> 1 ------ B<BR/> 1 ------ C<BR/> 2 ------ D<BR/> 2 ------ E<BR/> 3 ------ C<BR/> <...
5
2010-03-17T16:31:17Z
9,823,239
<p>This worked for me using both Microsoft Access VBA and Microsoft Excel VBA. It isn't very efficient code, but it works. I was able to open the resultant file in both Access and Excel.</p> <p>Set the <code>sDBF*</code> and <code>sOutDBF*</code> variables to tailor this to your own custom paths.</p> <pre><code>Sub V...
2
2012-03-22T13:27:46Z
[ "python", "vba" ]
concatenate multi values in one record without duplication
2,464,031
<p>I have a dbf table like below which is the result of one to many join from two tables. I want to have unique zone values from one Taxlot id field.</p> <p>table name: input table<br/> tid ----- zone<br/> 1 ------ A<BR/> 1 ------ A<BR/> 1 ------ B<BR/> 1 ------ C<BR/> 2 ------ D<BR/> 2 ------ E<BR/> 3 ------ C<BR/> <...
5
2010-03-17T16:31:17Z
9,839,073
<p>instead of this:</p> <pre><code>taxIdZoningDict = {} searchRows = gp.searchcursor(inputTbl) searchRow = searchRows.next() while searchRow: if searchRow.TID in taxIdZoningDict: taxIdZoningDict[searchRow.TID].add(searchRow.ZONE) else: taxIdZoningDict[searchRow.TID] = set() #a set prevents dulpicates...
1
2012-03-23T12:19:37Z
[ "python", "vba" ]
Sikuli List of Functions & Operators
2,464,333
<p>I've just discovered <a href="http://groups.csail.mit.edu/uid/sikuli/index.shtml">Sikuli</a>, and would like to see a comprehensive functions list without digging through the online-examples and demos. </p> <p>Has anyone found such a list?</p> <p>Furthermore, apparently Sikuli supports more complex loops and funct...
6
2010-03-17T17:13:20Z
2,502,253
<p>All the docs can be found at <a href="http://doc.sikuli.org/" rel="nofollow">the sikuli home page</a>.</p>
1
2010-03-23T17:41:35Z
[ "python", "list", "function", "sikuli", "operations" ]
Sikuli List of Functions & Operators
2,464,333
<p>I've just discovered <a href="http://groups.csail.mit.edu/uid/sikuli/index.shtml">Sikuli</a>, and would like to see a comprehensive functions list without digging through the online-examples and demos. </p> <p>Has anyone found such a list?</p> <p>Furthermore, apparently Sikuli supports more complex loops and funct...
6
2010-03-17T17:13:20Z
5,533,530
<p>Excellent, you found the docs. Have you checked their launchpad project for code examples? If not, sign up <a href="https://launchpad.net/sikuli" rel="nofollow">https://launchpad.net/sikuli</a> Questions can be asked and answers given. There are lots of good code examples as well. Beware of the idiotic drive...
0
2011-04-04T00:32:23Z
[ "python", "list", "function", "sikuli", "operations" ]
Sikuli List of Functions & Operators
2,464,333
<p>I've just discovered <a href="http://groups.csail.mit.edu/uid/sikuli/index.shtml">Sikuli</a>, and would like to see a comprehensive functions list without digging through the online-examples and demos. </p> <p>Has anyone found such a list?</p> <p>Furthermore, apparently Sikuli supports more complex loops and funct...
6
2010-03-17T17:13:20Z
13,902,436
<p>Sikuli seems to have moved from the MIT website to <a href="http://www.sikuli.org" rel="nofollow">http://www.sikuli.org</a> where the links to demos and documentation actually do work.</p>
0
2012-12-16T14:52:37Z
[ "python", "list", "function", "sikuli", "operations" ]
Sikuli List of Functions & Operators
2,464,333
<p>I've just discovered <a href="http://groups.csail.mit.edu/uid/sikuli/index.shtml">Sikuli</a>, and would like to see a comprehensive functions list without digging through the online-examples and demos. </p> <p>Has anyone found such a list?</p> <p>Furthermore, apparently Sikuli supports more complex loops and funct...
6
2010-03-17T17:13:20Z
20,498,662
<p>I am guessing you were looking for this page:</p> <p><a href="http://doc.sikuli.org/genindex.html" rel="nofollow">The General API Index</a></p> <p>It took me a while to find it when I was first looking into Sikuli. It explains the API of the classes and functions included with Sikuli. Its the next place to go af...
1
2013-12-10T15:38:48Z
[ "python", "list", "function", "sikuli", "operations" ]
Call macro from Python script?
2,464,442
<p>One of our page templates is made up of a bunch of macros. These items are a bunch of html tables.</p> <p>Now, I want a couple of these tables in a Python script to create a PDF. Is there a way call a macro from a Python script and get back the HTML that is produced?</p> <p>If so, can you explain?</p> <p>Thanks E...
1
2010-03-17T17:32:31Z
2,464,507
<p>I'd probably use <code>urllib.urlopen(url)</code>, pull the data from the page back to python and use <code>BeautifulSoup</code> to pull the table(s) out of the HTML... And then render that to PDF with <code>XHTML2PDF</code> (<code>pisa.ho</code>).</p> <p>There might be a simpler way but for me, this would be the l...
0
2010-03-17T17:41:13Z
[ "python", "zope" ]
Call macro from Python script?
2,464,442
<p>One of our page templates is made up of a bunch of macros. These items are a bunch of html tables.</p> <p>Now, I want a couple of these tables in a Python script to create a PDF. Is there a way call a macro from a Python script and get back the HTML that is produced?</p> <p>If so, can you explain?</p> <p>Thanks E...
1
2010-03-17T17:32:31Z
2,466,236
<p>Maybe you could create a new template including (use-macro) just the macros you want to access from python and then use z3c.pt.pagetemplate.PageTemplateFile() to render it?</p> <p>Actually, it might be possible (and certainly easier) to use chameleon.zpt.template.PageTemplate('&lt;div tal:use-macro="&lt;your-macro-...
0
2010-03-17T22:02:31Z
[ "python", "zope" ]
Extract strings in python
2,464,482
<p>Basically, I want to extract the strings "AAA", "BBB", "CCC", "DDD" from a text file..</p> <pre><code>...... (other text goes here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='textfont'&gt;AAA&lt;/font&gt;&lt;/TD&gt; ..... (useless text here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='tex...
0
2010-03-17T17:38:02Z
2,464,498
<p>You want <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>:</p> <pre><code>from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(your_file) soup.find("font", "textfont") </code></pre>
0
2010-03-17T17:40:08Z
[ "python", "string", "text-extraction" ]
Extract strings in python
2,464,482
<p>Basically, I want to extract the strings "AAA", "BBB", "CCC", "DDD" from a text file..</p> <pre><code>...... (other text goes here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='textfont'&gt;AAA&lt;/font&gt;&lt;/TD&gt; ..... (useless text here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='tex...
0
2010-03-17T17:38:02Z
2,464,555
<p>You could write a REGEX but it would be "parsing" the HTML to some extent. The problem with writing regular expressions for HTML is HTML is a mess. It's rarely perfect and this causes problems when you rely on it for data.</p> <p>I would personally use BeautifulSoup. It does do more than you're asking but also at s...
2
2010-03-17T17:48:54Z
[ "python", "string", "text-extraction" ]
Extract strings in python
2,464,482
<p>Basically, I want to extract the strings "AAA", "BBB", "CCC", "DDD" from a text file..</p> <pre><code>...... (other text goes here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='textfont'&gt;AAA&lt;/font&gt;&lt;/TD&gt; ..... (useless text here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='tex...
0
2010-03-17T17:38:02Z
2,464,569
<pre><code>def foo(): input_file = open("myfile.txt", 'r') input = ''.join(input_file.readlines()) looking_for = ['AAA', 'BBB', 'CCC', 'DDD'] have = [] for thing in looking_for: if thing in input: have.append(thing) return have </code></pre>
0
2010-03-17T17:50:55Z
[ "python", "string", "text-extraction" ]
Extract strings in python
2,464,482
<p>Basically, I want to extract the strings "AAA", "BBB", "CCC", "DDD" from a text file..</p> <pre><code>...... (other text goes here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='textfont'&gt;AAA&lt;/font&gt;&lt;/TD&gt; ..... (useless text here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='tex...
0
2010-03-17T17:38:02Z
2,464,571
<p>In a case like this it's, attempt regex for it ( which will be really had ), use a prewritten library, or do it your self with a <code>f = open() f.read()</code> and your own parser.</p>
0
2010-03-17T17:51:17Z
[ "python", "string", "text-extraction" ]
Extract strings in python
2,464,482
<p>Basically, I want to extract the strings "AAA", "BBB", "CCC", "DDD" from a text file..</p> <pre><code>...... (other text goes here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='textfont'&gt;AAA&lt;/font&gt;&lt;/TD&gt; ..... (useless text here)..... &lt;TD align="left" class=texttd&gt;&lt;font class='tex...
0
2010-03-17T17:38:02Z
2,464,728
<p>If you just want to get the data from inside all of the tags in the HTML document, while dropping all the tags themselves, you could do something like this:</p> <pre><code>import HTMLParser class DataOnlyParser(HTMLParser.HTMLParser): def parse(self, text): self.result = [] self.feed(text) ...
0
2010-03-17T18:13:01Z
[ "python", "string", "text-extraction" ]
Can someone explain what exactly this error means,TypeError: issubclass() arg 1 must be a class
2,464,568
<p>I have zero idea as to why I'm getting this error.</p>
-2
2010-03-17T17:50:44Z
2,464,578
<p>It means that you don't provide a class as argument for <code>issubclass()</code>. Both arguments have to be classes. Second argument can also be a tuple of classes.</p> <p><strong>If you show the code that throws this error, we can help further.</strong></p> <hr> <p>From the <a href="http://docs.python.org/libra...
2
2010-03-17T17:52:00Z
[ "python" ]
Can someone explain what exactly this error means,TypeError: issubclass() arg 1 must be a class
2,464,568
<p>I have zero idea as to why I'm getting this error.</p>
-2
2010-03-17T17:50:44Z
2,464,584
<p>The first argument to <code>issubclass()</code> needs to be of type "class".</p> <p><a href="http://pyref.infogami.com/issubclass" rel="nofollow">http://pyref.infogami.com/issubclass</a></p>
0
2010-03-17T17:52:50Z
[ "python" ]
Can someone explain what exactly this error means,TypeError: issubclass() arg 1 must be a class
2,464,568
<p>I have zero idea as to why I'm getting this error.</p>
-2
2010-03-17T17:50:44Z
2,464,622
<p>as people said, the 2 arguments of <code>issubclass()</code> should be classes, not instances of an object.</p> <p>consider this sample:</p> <pre><code>&gt;&gt;&gt; issubclass( 1, int ) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: issubclass() arg 1 must be a clas...
3
2010-03-17T17:58:31Z
[ "python" ]
Can someone explain what exactly this error means,TypeError: issubclass() arg 1 must be a class
2,464,568
<p>I have zero idea as to why I'm getting this error.</p>
-2
2010-03-17T17:50:44Z
2,464,634
<p>Basically this method tells you if the first parameter is a subclass of the second. So naturally, both your parameters need to be classes. It appears from your call, that you have called <code>issubclass</code> without any parameters, which confuses the interpreter.</p> <p>Calling <code>issubclass</code> is like as...
0
2010-03-17T17:59:43Z
[ "python" ]
Python: Matching & Stripping port number from socket data
2,464,670
<p>I have data coming in to a python server via a socket. Within this data is the string '<code>&lt;port&gt;80&lt;/port&gt;</code>' or which ever port is being used.</p> <p>I wish to extract the port number into a variable. The data coming in is not XML, I just used the tag approach to identifying data for future XML ...
0
2010-03-17T18:04:31Z
2,464,709
<p>Regex can't parse XML and shouldn't be used to parse <em>fake</em> XML. You should do one of</p> <ul> <li>Use a serialization method that is nicer to work with to start with, such as JSON or an ini file with the <code>ConfigParser</code> module.</li> <li><em>Really use XML</em> and not something that just sort of l...
1
2010-03-17T18:10:24Z
[ "python", "sockets" ]
Python: Matching & Stripping port number from socket data
2,464,670
<p>I have data coming in to a python server via a socket. Within this data is the string '<code>&lt;port&gt;80&lt;/port&gt;</code>' or which ever port is being used.</p> <p>I wish to extract the port number into a variable. The data coming in is not XML, I just used the tag approach to identifying data for future XML ...
0
2010-03-17T18:04:31Z
2,465,024
<p>Though Mike Graham is correct, using regex for xml is not 'recommended', the following will work:</p> <pre><code>(I have defined searchType as 'd' for numerals) searchStr = 'port' if searchType == 'd': retPattern = '(&lt;%s&gt;)(\d+)(&lt;/%s&gt;)' else: retPattern = '(&lt;%s&gt;)(.+?)(&lt;/%s&gt;)' search...
0
2010-03-17T18:52:59Z
[ "python", "sockets" ]
S3 Backup Memory Usage in Python
2,464,685
<p>I currently use WebFaction for my hosting with the basic package that gives us 80MB of RAM. This is more than adequate for our needs at the moment, apart from our backups. We do our own backups to S3 once a day. </p> <p>The backup process is this: dump the database, tar.gz all the files into one backup named with t...
1
2010-03-17T18:06:12Z
2,464,837
<p>don't read the whole file into your filedata variable. you could use a loop and then just read ~60 MB and submit them to amazon.</p> <pre><code>backup = open(filename, 'rb') while True: part_of_file = backup.read(60000000) # not exactly 60 MB.... response = connection.put() # submit part_of_file here to ama...
0
2010-03-17T18:26:44Z
[ "python", "memory", "upload", "amazon-s3" ]
S3 Backup Memory Usage in Python
2,464,685
<p>I currently use WebFaction for my hosting with the basic package that gives us 80MB of RAM. This is more than adequate for our needs at the moment, apart from our backups. We do our own backups to S3 once a day. </p> <p>The backup process is this: dump the database, tar.gz all the files into one backup named with t...
1
2010-03-17T18:06:12Z
5,265,227
<p>It's a little late but I had to solve the same problem so here's my answer.</p> <p>Short answer: in Python 2.6+ yes! This is because the <code>httplib</code> supports file-like objects as of v2.6. So all you need is...</p> <pre><code>fileobj = open(filename, 'rb') content_type = mimetypes.guess_type(filename)[0] i...
2
2011-03-10T20:02:27Z
[ "python", "memory", "upload", "amazon-s3" ]
How to implement a master/watchdog script in python?
2,464,704
<p>I need it to open 10 processes, and each time one of them finishes I want to wait few seconds and start another one. It seems pretty simple, but somehow I can't get it to work.</p>
2
2010-03-17T18:09:49Z
2,464,752
<p>I've done this same thing to process web statistics using a semaphore. Essentially, as processes are created, the semaphore is incremented. When they exit, it's decremented. The creation process is blocked when the semaphore blocks. </p> <p>This actually fires off threads, which run external processes down execu...
1
2010-03-17T18:16:51Z
[ "python", "subprocess", "watchdog" ]
How to implement a master/watchdog script in python?
2,464,704
<p>I need it to open 10 processes, and each time one of them finishes I want to wait few seconds and start another one. It seems pretty simple, but somehow I can't get it to work.</p>
2
2010-03-17T18:09:49Z
2,464,856
<p>I'm not 100% clear on what you're trying to accomplish, but have you looked at the <code>multiprocessing</code> module, specifically <a href="http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers" rel="nofollow">using a pool of workers</a>?</p>
2
2010-03-17T18:29:06Z
[ "python", "subprocess", "watchdog" ]
Capture output from a mysql select statement using python
2,464,792
<p>Using Python2.4 I want to capture output from a mysql command. One caveat is that I need to pipe the SQL statement using an echo.</p> <pre><code>echo 'SELECT user FROM mysql.user;' | mysql </code></pre> <p>I see example using call, os.system, popen but what is best to use for my version of python and capturing the...
0
2010-03-17T18:21:40Z
2,465,364
<p>The subprocess module is the most flexible tool for running commands and controlling the input and output. The following runs a command and captures the output as a list of lines:</p> <pre><code>import subprocess p = subprocess.Popen(['/bin/bash', '-c', "echo 'select user from mysql.user;' | mysql" ], stdout=...
1
2010-03-17T19:50:35Z
[ "python" ]