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
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,747,884
<p><a href="http://seleniumhq.org/" rel="nofollow">Selenium</a> is a very good tool to automate browser testing</p> <p>Since you mentioned Ruby in your tags, I also recommend <a href="http://wiki.github.com/brynary/webrat" rel="nofollow">Webrat</a> which is a nice in-browser testing solution in Ruby.</p>
2
2009-11-17T10:22:09Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,748,121
<p>You can also control selenium using Selenium-RC's python binding. For example:</p> <pre><code>from selenium import selenium selenium = selenium("localhost", 4444, "*firefox", "http://www.google.com/") selenium.start() selenium.open("/") # open google.com selenium.type("q", "selenium rc") selenium.click...
4
2009-11-17T11:05:36Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,748,507
<p><a href="http://seleniumhq.org/"><code>Selenium</code></a> is a good way to go. For using it with Perl then use the <a href="http://search.cpan.org/dist/Test-WWW-Selenium/"><code>Test::WWW::Selenium</code></a> CPAN module.</p> <p>Here is <a href="http://search.cpan.org/dist/Test-WWW-Selenium/util/create%5Fwww%5Fse...
10
2009-11-17T12:22:22Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,749,404
<p>Here's another option, all written in Python and cross browsers for running AND recording tests: <a href="http://www.getwindmill.com/" rel="nofollow">Windmill</a></p>
2
2009-11-17T14:54:11Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,749,751
<p>In <a href="http://www.ibm.com/developerworks/web/library/wa-aj-testing/" rel="nofollow">this article</a>, Noah Gift does a good job presenting three main alternatives for web app integration testing: Windmill, Selenium and Twill. Twill doesn't do Javascript, so that leaves Selenium and Windmill as your main possib...
6
2009-11-17T15:42:45Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,749,850
<p>Another great tool for browser testing which is built as Ruby library and uses Ruby for scripting is <a href="http://watir.com/" rel="nofollow">Watir</a>. There is also a firefox plugin for watir just like selenium called<br> Firewatir hosted on google code</p>
0
2009-11-17T15:58:49Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,888,610
<p><a href="http://testplan.brainbrain.net/" rel="nofollow">TestPlan</a> is a great tool for general purpose web testing. It provides both a display-less backend and Selenium. The Selenium backend should take care of testing in all the popular browsers. It also has its own scripting language which makes it quick to wri...
1
2009-12-11T14:56:59Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
1,747,827
<p>In Python 2.6 and earlier, the dict constructor can receive an iterable of key/value pairs:</p> <pre><code>d = dict((key, value) for (key, value) in iterable) </code></pre> <p>From Python 2.7 and 3 onwards, you can just use the <a href="http://www.python.org/dev/peps/pep-0274/">dict comprehension syntax</a> direct...
1,129
2009-11-17T10:09:32Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
1,747,888
<p>In Python 3 / Python 2.7+ dict comprehensions works like this:</p> <pre><code>d = {k:v for k, v in iterable} </code></pre> <p>For Python 2.6 and earlier, see @fortan's answer.</p>
123
2009-11-17T10:22:45Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
1,747,904
<p>Use Python dict comprehensions. Here's the page to know more about it: <em><a href="http://www.python.org/dev/peps/pep-0274/" rel="nofollow">Dict Comprehensions</a></em>.</p>
10
2009-11-17T10:27:29Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
16,863,042
<p>In fact, you don't even need to iterate over the iterable if it already comprehends some kind of mapping, the dict constructor doing it graciously for you:</p> <pre><code>&gt;&gt;&gt; ts = [(1, 2), (3, 4), (5, 6)] &gt;&gt;&gt; dict(ts) {1: 2, 3: 4, 5: 6} &gt;&gt;&gt; gen = ((i, i+1) for i in range(1, 6, 2)) &gt;&gt...
16
2013-05-31T17:48:45Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
31,069,124
<p><strong>Simple for older version &lt; 2.7</strong></p> <pre><code>d = dict((i,True) for i in [1,2,3]) </code></pre> <p><strong>for version >= 2.7</strong></p> <pre><code>d = {i: True for i in [1,2,3]} </code></pre>
3
2015-06-26T09:05:46Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
33,005,845
<p>In Python 2.7, it goes like:</p> <pre><code>&gt;&gt;&gt; list1, list2 = ['a', 'b', 'c'], [1,2,3] &gt;&gt;&gt; dict( zip( list1, list2)) {'a': 1, 'c': 3, 'b': 2} </code></pre> <p><strong>Zip them</strong>!</p>
13
2015-10-08T02:59:01Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
34,802,311
<p>To add onto @fortran's answer, if you want to iterate over a list of keys <code>key_list</code> as well as a list of values <code>value_list</code>:</p> <pre><code>d = dict((key, value) for (key, value) in zip(key_list, value_list)) </code></pre> <p>or</p> <pre><code>d = {(key, value) for (key, value) in zip(key_...
4
2016-01-15T00:23:57Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Create a dictionary with list comprehension in Python
1,747,817
<p>I like the Python list comprehension syntax.</p> <p>Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:</p> <pre><code>mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work :( </code></pre>
692
2009-11-17T10:07:53Z
35,179,457
<p>Try this,</p> <pre><code>def get_dic_from_two_lists(keys, values): return { keys[i] : values[i] for i in range(len(keys)) } </code></pre> <p>Assume we have two lists <strong>country</strong> and <strong>capital</strong></p> <pre><code>country = ['India', 'Pakistan', 'China'] capital = ['New Delhi', 'Islamabad...
2
2016-02-03T14:15:14Z
[ "python", "dictionary", "language-features", "list-comprehension" ]
Multiprocessing Pool inside Process time out
1,747,963
<p>When ever I use the following code the pool result always returns a timeout, is there something logically incorrect I am doing?</p> <pre><code>from multiprocessing import Pool, Process, cpu_count def add(num): return num+1 def add_wrap(num): new_num = ppool.apply_async(add, [num]) print new_num.get(timeout=...
3
2009-11-17T10:37:36Z
1,748,335
<p>You can't pass Pool objects between processes.</p> <p>If you try this code, Python will raise a exception : 'NotImplementedError: pool objects cannot be passed between processes or pickled'.</p> <pre><code>from multiprocessing import Queue, Pool q = Queue() ppool = Pool(processes=2) ...
2
2009-11-17T11:49:40Z
[ "python", "process", "timeout", "multiprocessing", "pool" ]
Properties dictionary for Events in the Google Wave Python API
1,747,986
<p>The Google Wave documentation contains the <a href="http://code.google.com/apis/wave/extensions/robots/index.html" rel="nofollow">Robot Events</a>, but doesn't list what values will be put into the properties dictionary. Is this documented anywhere?</p>
2
2009-11-17T10:42:38Z
1,748,005
<p>They are listed in <a href="http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html" rel="nofollow">API Reference documentation</a>, in the <code>waveapi.events</code> module.</p> <p>Here's the list:</p> <pre><code>WAVELET_BLIP_CREATED WAVELET_BLIP_REMOVED WAVELET_PARTICIPANTS_CHANGED WAVELET_SE...
0
2009-11-17T10:45:47Z
[ "python", "events", "google-wave" ]
Properties dictionary for Events in the Google Wave Python API
1,747,986
<p>The Google Wave documentation contains the <a href="http://code.google.com/apis/wave/extensions/robots/index.html" rel="nofollow">Robot Events</a>, but doesn't list what values will be put into the properties dictionary. Is this documented anywhere?</p>
2
2009-11-17T10:42:38Z
1,858,406
<p>I had the same question and found some hints in the following Google group thread: <a href="http://groups.google.com/group/google-wave-api/browse%5Fthread/thread/8d19dbcb6f2147cc" rel="nofollow">http://groups.google.com/group/google-wave-api/browse%5Fthread/thread/8d19dbcb6f2147cc</a></p> <p>For now, I think the cl...
3
2009-12-07T07:32:09Z
[ "python", "events", "google-wave" ]
Cron in Google App Engine
1,748,074
<p>I have made an app using Google App Engine in python of weekly Project and assessment report submitting. </p> <p>I want to check that on Friday who have submitted the report and who don't just send the scheduled notification mail that he haven't submitted the report in last week.</p> <p>but i don't want to send th...
-1
2009-11-17T10:56:08Z
1,748,684
<p>Not sure what you want, but anything you can do with cron can be done via TaskQueues in GAE, so read this <a href="http://code.google.com/appengine/docs/python/taskqueue/" rel="nofollow">http://code.google.com/appengine/docs/python/taskqueue/</a></p> <p><code>App Engine applications can perform background processin...
0
2009-11-17T12:55:49Z
[ "python", "google-app-engine", "cron" ]
Cron in Google App Engine
1,748,074
<p>I have made an app using Google App Engine in python of weekly Project and assessment report submitting. </p> <p>I want to check that on Friday who have submitted the report and who don't just send the scheduled notification mail that he haven't submitted the report in last week.</p> <p>but i don't want to send th...
-1
2009-11-17T10:56:08Z
1,749,793
<p>Hard to fathom what you want (your English is very hard to parse), but anyway, besides Task Queues which are much more flexible and powerful (and may be harder to use for simple jobs that cron functionality covers perfectly), you can use cron to schedule App Engine tasks in Python by following the instructions <a hr...
2
2009-11-17T15:47:41Z
[ "python", "google-app-engine", "cron" ]
Scheduling Filter on Database with Time Interval
1,748,130
<p>Let's you have a science experiment called <code>Weather</code> and it records general information about the weather, one of which is recording the <code>humidity</code> every minute. After say 10 hours, you'll have 600 database values stored.</p> <pre><code>Weather.objects.filter().exclude(time__lt = commence).exc...
1
2009-11-17T11:07:15Z
1,748,151
<p>SQL doesn't have a way to ask for every tenth, so ORMs won't typically give you a way to express that need. You could do that work in Python:</p> <pre><code>samples = list(Weather.objects.filter().exclude(time__lt=commence).exclude(time__gt=cease)) for s10 in samples[::10]: # do something with every tenth... <...
2
2009-11-17T11:12:07Z
[ "python", "django", "filter" ]
Python: Connect blender with WinTracker 2
1,748,482
<p>i am trying to do project about <strong>control model</strong> in <strong>Blender</strong> by using <strong>WinTracker machine</strong> ,</p> <p>But I don't know how to connect it with <code>Blender Game Engine</code></p> <p>Please help.</p>
0
2009-11-17T12:19:04Z
2,397,249
<p>You must write the plug-in for blender and used the wintracker driver. It is ready for c Lagrange. but you have "wintracker2"?</p> <p>I wanted to buy it but the company said "it's not ready to seal".</p>
0
2010-03-07T17:57:09Z
[ "python", "blender" ]
Boolean in Python
1,748,641
<p>Does Python actually contain a Boolean value? I know that you can do:</p> <pre><code>checker = 1 if checker: #dostuff </code></pre> <p>But I'm quite pedantic and enjoy seeing booleans in Java. For instance:</p> <pre><code>Boolean checker; if (someDecision) { checker = true; } if(checker) { //some stuf...
48
2009-11-17T12:48:39Z
1,748,651
<pre><code>checker = None # not necessary if some_decision: checker = True if checker: # some stuff </code></pre> <p>[Edit]</p> <p>For more information: <a href="http://docs.python.org/library/functions.html#bool">http://docs.python.org/library/functions.html#bool</a></p> <p>Your code works too, since 1 is...
64
2009-11-17T12:51:13Z
[ "python", "boolean" ]
Boolean in Python
1,748,641
<p>Does Python actually contain a Boolean value? I know that you can do:</p> <pre><code>checker = 1 if checker: #dostuff </code></pre> <p>But I'm quite pedantic and enjoy seeing booleans in Java. For instance:</p> <pre><code>Boolean checker; if (someDecision) { checker = true; } if(checker) { //some stuf...
48
2009-11-17T12:48:39Z
1,748,672
<p>The boolean builtins are capitalized: <code>True</code> and <code>False</code>.</p> <p>Note also that you can do <code>checker = bool(some_decision)</code> as a bit of shorthand -- <a href="http://docs.python.org/library/functions.html#bool"><code>bool</code></a> will only ever return <code>True</code> or <code>Fal...
61
2009-11-17T12:54:43Z
[ "python", "boolean" ]
Boolean in Python
1,748,641
<p>Does Python actually contain a Boolean value? I know that you can do:</p> <pre><code>checker = 1 if checker: #dostuff </code></pre> <p>But I'm quite pedantic and enjoy seeing booleans in Java. For instance:</p> <pre><code>Boolean checker; if (someDecision) { checker = true; } if(checker) { //some stuf...
48
2009-11-17T12:48:39Z
1,748,722
<p>Boolean types are defined in documentation:<br /> <a href="http://docs.python.org/library/stdtypes.html#boolean-values" rel="nofollow">http://docs.python.org/library/stdtypes.html#boolean-values</a></p> <p><em>Quoted from doc:</em></p> <blockquote> <p>Boolean values are the two constant objects False and True. T...
4
2009-11-17T13:02:06Z
[ "python", "boolean" ]
Boolean in Python
1,748,641
<p>Does Python actually contain a Boolean value? I know that you can do:</p> <pre><code>checker = 1 if checker: #dostuff </code></pre> <p>But I'm quite pedantic and enjoy seeing booleans in Java. For instance:</p> <pre><code>Boolean checker; if (someDecision) { checker = true; } if(checker) { //some stuf...
48
2009-11-17T12:48:39Z
1,748,727
<p><code>True</code> ... and <code>False</code> obviously.</p> <p>Otherwise, <code>None</code> evaluates to False, as does the integer <code>0</code> and also the float <code>0.0</code> (although I wouldn't use floats like that). Also, empty lists <code>[]</code>, empty tuplets <code>()</code>, and empty strings <code...
7
2009-11-17T13:02:57Z
[ "python", "boolean" ]
Boolean in Python
1,748,641
<p>Does Python actually contain a Boolean value? I know that you can do:</p> <pre><code>checker = 1 if checker: #dostuff </code></pre> <p>But I'm quite pedantic and enjoy seeing booleans in Java. For instance:</p> <pre><code>Boolean checker; if (someDecision) { checker = true; } if(checker) { //some stuf...
48
2009-11-17T12:48:39Z
1,748,767
<p>Yes, there is a <code>bool</code> data type (which inherits from <code>int</code> and has only two values: <code>True</code> and <code>False</code>).</p> <p>But also Python has the <code>boolean-able</code> concept for every object, which is used when function <code>bool([x])</code> is called.</p> <p>See more: <a ...
1
2009-11-17T13:10:44Z
[ "python", "boolean" ]
Does Python use NFAs for regular expression evaluation in the re module?
1,748,853
<p>Does anybody know if Python (any version) used NFAs (Non-Deterministic Finite Automata) to evaluate regular expressions or does it use some other mechanism? Please provide links/reference if available. </p>
5
2009-11-17T13:25:37Z
1,748,915
<p>NFA.</p> <p>See Friedl's <em>Mastering Regular Expressions</em>, 3rd edition, chapter 4 - table 4-1, page 145.</p> <p>Google books has <a href="http://books.google.com/books?id=NYEX-Q9evKoC&amp;pg=PA145&amp;dq=%22table+4-1%22+mastering+regular+expressions#v=onepage&amp;q=&amp;f=false">a preview</a> to it.</p>
5
2009-11-17T13:35:49Z
[ "python", "regex", "nfa" ]
Does Python use NFAs for regular expression evaluation in the re module?
1,748,853
<p>Does anybody know if Python (any version) used NFAs (Non-Deterministic Finite Automata) to evaluate regular expressions or does it use some other mechanism? Please provide links/reference if available. </p>
5
2009-11-17T13:25:37Z
5,460,677
<p>This should take less than a ms on a DFA:</p> <pre><code>$ time python3 -c 'import re; re.match("a?"*25+"a"*25, "a"*25)' real 0m7.273s </code></pre> <p>Change 25 with 100 and it won't terminate for a lifetime.</p> <p>Here is how it looks on a DFA (grep):</p> <pre><code>$ time echo "aaaaaaaaaaaaaaaaaaaaaaaaaaa...
3
2011-03-28T14:44:15Z
[ "python", "regex", "nfa" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,748,934
<p>yes, it is enough</p>
-2
2009-11-17T13:38:09Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,748,935
<p>Well, that will tell you whether they're definitely different or <em>probably</em> the same. It's <em>possible</em> for two files to have the same hash but not actually have the same data... just very unlikely.</p> <p>In your situation, what is the impact if you get a false positive (i.e. if you think they're the s...
13
2009-11-17T13:38:09Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,748,938
<p>If you're on a system with md5sum, that's probably good enough.</p> <p>You can do it with Python standard libraries -- checkout out <code>hashlib</code>.</p>
3
2009-11-17T13:38:30Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,748,941
<p>Depends if you feel comfortable with the probability of collision on the MD5 algorithm. Just note it is highly unlikely: so yes, go ahead.</p>
0
2009-11-17T13:38:40Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,748,996
<p>If you want to do more than just detect if they differ, or don't trust the hashing solution, there are modules called <a href="http://docs.python.org/library/difflib.html">difflib</a> and <a href="http://docs.python.org/library/filecmp.html">filecmp</a> that doesn't rely on external programs.</p>
12
2009-11-17T13:46:25Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,749,019
<p>Of course there is a simple test that you should do before comparing the file content at all - if the files are different sizes, then they can not possibly be the same.</p> <p>Wouldn't it be more efficient to simply read each file and do a byte-by-byte comparison, avoiding the hashing algorithm altogether. This av...
7
2009-11-17T13:50:54Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,749,047
<p>If there is nobody maliciously trying to create collisions, then you would have to compare about 2<sup>64</sup> files before you would expect to see a <a href="http://en.wikipedia.org/wiki/Birthday%5Fproblem" rel="nofollow">collision by random chance</a>. However, it is possible for someone to carefully construct tw...
0
2009-11-17T13:53:08Z
[ "python", "file", "md5", "compare" ]
How to detect whether two files are identical in Python
1,748,923
<p>Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?</p>
4
2009-11-17T13:36:40Z
1,749,455
<p>A hash is useful if you are going to cache it (to compare many different files with each-other). If you just want to compare two files, it's a monstrous waste of cycles. After all - both files will be read in, and a lot of processing will be used on every bite.</p> <p>If it's a 1:1 compare, just use:</p> <pre><cod...
2
2009-11-17T15:01:29Z
[ "python", "file", "md5", "compare" ]
Unable to unpickle a file on Mac that was pickled on Windows
1,748,958
<p>I've got a simple class that I am pickling(dumping) to a file. On OS X this works fine, and on Windows this works fine.</p> <p>However, while on windows I can load/unpickle the object fine - when windows then pickles this file and saves it back to disk, it becomes unreadable on OS X (although in Windows it still be...
2
2009-11-17T13:40:30Z
1,748,972
<p>Pickle with the newest protocol version and open the files in binary mode in all cases. That should solve the problem.</p>
5
2009-11-17T13:42:24Z
[ "python", "windows", "osx", "pickle" ]
Unable to unpickle a file on Mac that was pickled on Windows
1,748,958
<p>I've got a simple class that I am pickling(dumping) to a file. On OS X this works fine, and on Windows this works fine.</p> <p>However, while on windows I can load/unpickle the object fine - when windows then pickles this file and saves it back to disk, it becomes unreadable on OS X (although in Windows it still be...
2
2009-11-17T13:40:30Z
1,748,998
<p>It will be line endings - if you are using ASCII pickle open file in ascii mode 'r' or 'w' - if you are using a binary pickle open in binary mode 'rb' 'wb'. From the docstring:</p> <blockquote> <p>The default protocol is 0, to be backwards compatible. (Protocol 0 is the only protocol that can be writ...
3
2009-11-17T13:47:27Z
[ "python", "windows", "osx", "pickle" ]
Named Pipes between C# and Python
1,749,001
<p>I'm trying to create a two-way communication channel between two programs (one in Python and another in C#)</p> <p>When I create a named pipe between two C# programs or two Python programs, everything is OK, but when I try to (for example) connect to the C# server from Python code, it does not work:</p> <p>C# code...
4
2009-11-17T13:48:02Z
1,749,371
<p>I think you are meant to use win32pipe.popen, not open.</p> <p>Also try: pipe.flush(), pipe.read(), and time.sleep(0.01). Sometimes IPC takes a while to sync up.</p> <p>I don't really know, that's my experience with the subprocess pipes. win32pipe might be different.</p>
0
2009-11-17T14:47:28Z
[ "c#", "python", "windows", "named-pipes" ]
Named Pipes between C# and Python
1,749,001
<p>I'm trying to create a two-way communication channel between two programs (one in Python and another in C#)</p> <p>When I create a named pipe between two C# programs or two Python programs, everything is OK, but when I try to (for example) connect to the C# server from Python code, it does not work:</p> <p>C# code...
4
2009-11-17T13:48:02Z
1,755,474
<p>OK, I fixed the problem. I should seek to position 0 of buffer.</p> <p>My Python code:</p> <pre><code> win32file.WriteFile(CLIENT_PIPE,"%d\r\n"%i ,None) win32file.FlushFileBuffers(CLIENT_PIPE) win32file.SetFilePointer(CLIENT_PIPE,0,win32file.FILE_BEGIN) i,s = win32file.ReadFile(CLIENT_PIPE,10,None) ...
1
2009-11-18T11:48:00Z
[ "c#", "python", "windows", "named-pipes" ]
Named Pipes between C# and Python
1,749,001
<p>I'm trying to create a two-way communication channel between two programs (one in Python and another in C#)</p> <p>When I create a named pipe between two C# programs or two Python programs, everything is OK, but when I try to (for example) connect to the C# server from Python code, it does not work:</p> <p>C# code...
4
2009-11-17T13:48:02Z
4,390,603
<p>According to <a href="http://msdn.microsoft.com/en-us/library/aa365590%28v=vs.85%29.aspx" rel="nofollow">MS</a>, <code>ConnectNamedPipe</code> is the "server-side function for accepting a connnection". That's why it never returns - it's waiting for a connection from a client. Here's some sample code showing C# as ...
1
2010-12-08T17:47:53Z
[ "c#", "python", "windows", "named-pipes" ]
How to implement restful webservice with python/django
1,749,005
<p>i try to setup a ubuntu server with web service that create by django/python , anyone have an resource/tutorial/example code</p>
3
2009-11-17T13:49:03Z
1,749,043
<p>See <a href="http://www.djangobook.com/en/2.0/chapter13/" rel="nofollow">the chapter on non-html content in the Django book</a>.</p>
1
2009-11-17T13:52:42Z
[ "python", "django", "web-services" ]
How to implement restful webservice with python/django
1,749,005
<p>i try to setup a ubuntu server with web service that create by django/python , anyone have an resource/tutorial/example code</p>
3
2009-11-17T13:49:03Z
1,749,100
<p>There is also <a href="http://bitbucket.org/jespern/django-piston/wiki/Home" rel="nofollow">piston</a>, which is a Django framework for creating RESTful APIs. It has a slight learning curve, but nicely fits into Django. </p> <p>If you want something more lightweight, Simon Willison has very <a href="http://www.dj...
6
2009-11-17T14:01:46Z
[ "python", "django", "web-services" ]
Remove one char from a string
1,749,283
<p>I'd like to remove one char from a string like this:</p> <pre><code>string = "ASDFVGHFJHRSFDZFDJKUYTRDSEADFDHDS" print len(string) </code></pre> <p>(33)</p> <p>So i would like to remove one random char in this string, and then have a len = 32 What's the best way to do so ?</p> <p>EDIT: thanks for your answers, ...
0
2009-11-17T14:31:06Z
1,749,319
<pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; s = "ASDFVGHFJHRSFDZFDJKUYTRDSEADFDHDS" &gt;&gt;&gt; i = random.randint(0, len(s)-1) &gt;&gt;&gt; print s[:i] + s[i+1:] ASDFVGHFJHRSFDZFDJKUYRDSEADFDHDS &gt;&gt;&gt; print s[i] T </code></pre> <p>Basically get a random number from 0 to len-1 of string and remove the c...
5
2009-11-17T14:37:52Z
[ "python", "string" ]
Remove one char from a string
1,749,283
<p>I'd like to remove one char from a string like this:</p> <pre><code>string = "ASDFVGHFJHRSFDZFDJKUYTRDSEADFDHDS" print len(string) </code></pre> <p>(33)</p> <p>So i would like to remove one random char in this string, and then have a len = 32 What's the best way to do so ?</p> <p>EDIT: thanks for your answers, ...
0
2009-11-17T14:31:06Z
1,749,325
<pre><code>import random index = random.randint(0, len(yourstring)-1) yourstring = yourstring[:index] + yourstring[index+1:] print yourstring[index] </code></pre>
3
2009-11-17T14:38:35Z
[ "python", "string" ]
Remove one char from a string
1,749,283
<p>I'd like to remove one char from a string like this:</p> <pre><code>string = "ASDFVGHFJHRSFDZFDJKUYTRDSEADFDHDS" print len(string) </code></pre> <p>(33)</p> <p>So i would like to remove one random char in this string, and then have a len = 32 What's the best way to do so ?</p> <p>EDIT: thanks for your answers, ...
0
2009-11-17T14:31:06Z
1,749,474
<pre><code>&gt;&gt;&gt; s="ASDFVGHFJHRSFDZFDJKUYTRDSEADFDHDS" &gt;&gt;&gt; r=random.randrange(len(string)) &gt;&gt;&gt; print s[:r]+s[r+1:] ASDFVGHJHRSFDZFDJKUYTRDSEADFDHDS </code></pre>
7
2009-11-17T15:04:37Z
[ "python", "string" ]
Making Python Use Code in My Directory (not that in /usr/...)
1,749,452
<p>I am trying to work on a Python library that is already installed on my (Ubuntu) system. I checked out that library, edited some files, and wrote a small script to test my changes. Even though I put my script in the same folder as that of the library, it seems Python is using the installed version instead (the one i...
2
2009-11-17T15:01:00Z
1,749,471
<p>You can dictate where <code>python</code> searches for modules using the <code>PYTHONPATH</code> environment variable:</p> <blockquote> <p>When a module named spam is imported, the interpreter searches for a file named spam.py in the current directory, and then in the list of directories specified by the ...
3
2009-11-17T15:04:24Z
[ "python", "path" ]
Making Python Use Code in My Directory (not that in /usr/...)
1,749,452
<p>I am trying to work on a Python library that is already installed on my (Ubuntu) system. I checked out that library, edited some files, and wrote a small script to test my changes. Even though I put my script in the same folder as that of the library, it seems Python is using the installed version instead (the one i...
2
2009-11-17T15:01:00Z
1,749,481
<p>It might work if you set the <code>PYTHONPATH</code> environment variable to include that directory, e.g.:</p> <pre><code>$ cd src $ export PYTHONPATH=./library_package $ python my_package/my_script.py </code></pre>
0
2009-11-17T15:05:12Z
[ "python", "path" ]
Making Python Use Code in My Directory (not that in /usr/...)
1,749,452
<p>I am trying to work on a Python library that is already installed on my (Ubuntu) system. I checked out that library, edited some files, and wrote a small script to test my changes. Even though I put my script in the same folder as that of the library, it seems Python is using the installed version instead (the one i...
2
2009-11-17T15:01:00Z
1,749,497
<p>Check the complete path that Python uses through <code>sys.path</code>. You should be able to add to the path (in front for precedence).</p> <p>Of course, you can also use PYTHONPATH environment variable or work-around using <code>.pth</code> files.</p>
1
2009-11-17T15:06:51Z
[ "python", "path" ]
Making Python Use Code in My Directory (not that in /usr/...)
1,749,452
<p>I am trying to work on a Python library that is already installed on my (Ubuntu) system. I checked out that library, edited some files, and wrote a small script to test my changes. Even though I put my script in the same folder as that of the library, it seems Python is using the installed version instead (the one i...
2
2009-11-17T15:01:00Z
1,749,805
<p>Lets consider a more general issue. In the /usr/share/pyshared/ there are lots of modules. You wish to override just one of the modules. Say the module name is xyz.py. And it happens to use other modules in /usr/shared/pyshared also. </p> <p>Say we create $HOME/mylibs and add $HOME to Python's sys.path.</p> <p>Now...
3
2009-11-17T15:51:10Z
[ "python", "path" ]
Making Python Use Code in My Directory (not that in /usr/...)
1,749,452
<p>I am trying to work on a Python library that is already installed on my (Ubuntu) system. I checked out that library, edited some files, and wrote a small script to test my changes. Even though I put my script in the same folder as that of the library, it seems Python is using the installed version instead (the one i...
2
2009-11-17T15:01:00Z
1,751,387
<pre><code>import sys from os.path import join, dirname, pardir sys.path.insert(0, join(dirname(__file__), pardir)) </code></pre> <p>This will check the <code>src</code> directory for any python modules, and will look there first. So even if you have a module with the same name installed elsewhere, this will cause py...
3
2009-11-17T20:02:46Z
[ "python", "path" ]
What's the most pythonic way of normalizing lineends in a string?
1,749,466
<p>Given a text-string of unknown source, how does one best rewrite it to have a known lineend-convention?</p> <p>I usually do:</p> <pre><code>lines = text.splitlines() text = '\n'.join(lines) </code></pre> <p>... but this doesn't handle "mixed" text-files of utterly confused conventions (Yes, they still exist!).</p...
5
2009-11-17T15:02:46Z
1,749,553
<blockquote> <p>... but this doesn't handle "mixed" text-files of utterly confused conventions (Yes, they still exist!)</p> </blockquote> <p>Actually it should work fine:</p> <pre><code>&gt;&gt;&gt; s = 'hello world\nline 1\r\nline 2' &gt;&gt;&gt; s.splitlines() ['hello world', 'line 1', 'line 2'] &gt;&gt;&gt; '\...
7
2009-11-17T15:14:46Z
[ "python", "newline", "line-breaks" ]
What's the most pythonic way of normalizing lineends in a string?
1,749,466
<p>Given a text-string of unknown source, how does one best rewrite it to have a known lineend-convention?</p> <p>I usually do:</p> <pre><code>lines = text.splitlines() text = '\n'.join(lines) </code></pre> <p>... but this doesn't handle "mixed" text-files of utterly confused conventions (Yes, they still exist!).</p...
5
2009-11-17T15:02:46Z
1,749,584
<p>Are there even more convetions than <code>\r\n\</code> and <code>\n</code>? Simply replacing <code>\r\n</code> is enough if you dont want lines. </p> <pre><code>only_newlines = mixed.replace('\r\n','\n') </code></pre>
0
2009-11-17T15:20:08Z
[ "python", "newline", "line-breaks" ]
What's the most pythonic way of normalizing lineends in a string?
1,749,466
<p>Given a text-string of unknown source, how does one best rewrite it to have a known lineend-convention?</p> <p>I usually do:</p> <pre><code>lines = text.splitlines() text = '\n'.join(lines) </code></pre> <p>... but this doesn't handle "mixed" text-files of utterly confused conventions (Yes, they still exist!).</p...
5
2009-11-17T15:02:46Z
1,749,887
<pre><code>mixed.replace('\r\n', '\n').replace('\r', '\n') </code></pre> <p>should handle all possible variants.</p>
11
2009-11-17T16:04:07Z
[ "python", "newline", "line-breaks" ]
Python, C: redirected stdout fires [Errno 9]
1,749,762
<p>I try to log all the output of a program written in Python and C. However, printing from Python causes <code>IOError: [Errno 9] Bad file descriptor</code></p> <p>Please, does anyone know what the problem is and how to fix it?</p> <p>PS: It's on Windows XP, Python 2.6 and MinGW GCC</p> <pre><code>#include &lt;wind...
2
2009-11-17T15:44:29Z
1,749,803
<p>I think it could be to do with different C runtimes. I know you can't pass file descriptors between different C runtimes - Python is built with MSVC (you will need to check which version) - so you could try to make MinGW build against the same C runtime - I think there is options to do this in MinGW like -lmsvcrt80 ...
2
2009-11-17T15:50:37Z
[ "python", "c", "windows", "stdout" ]
Python - Create html page with hyperlinks from os.listdir
1,749,769
<p>I have a script that creates a folder called "videos" on a USB drive, moves 6,500 WMV files over to the "videos" folder. Then it's suppose to create an HTML page with hyperlinks to each file. Here is my current example that's broken. I'm trying to have it crawl the videos directory and create an HTML page with hyper...
1
2009-11-17T15:45:13Z
1,749,826
<p>Don't do <code>f.writelines(videoDirectory)</code> and then regex. Besides you're only printing to the console with that regex subsitution.</p> <p>Do </p> <pre><code>videoDirectory = os.listdir("videos") f = open("videos.html", "w") f.write('&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;ul&gt;' f.writel...
1
2009-11-17T15:54:13Z
[ "python" ]
Python - Create html page with hyperlinks from os.listdir
1,749,769
<p>I have a script that creates a folder called "videos" on a USB drive, moves 6,500 WMV files over to the "videos" folder. Then it's suppose to create an HTML page with hyperlinks to each file. Here is my current example that's broken. I'm trying to have it crawl the videos directory and create an HTML page with hyper...
1
2009-11-17T15:45:13Z
1,749,831
<pre><code>import cgi def is_video_file(filename): return filename.endswith(".wmv") # customize however you like def createHTML(): videoDirectory = os.listdir("videos") with open("videos.html", "w") as f: f.write("&lt;html&gt;&lt;body&gt;&lt;ul&gt;\n") for filename in videoDirectory: if is_video_f...
9
2009-11-17T15:55:19Z
[ "python" ]
Python - Create html page with hyperlinks from os.listdir
1,749,769
<p>I have a script that creates a folder called "videos" on a USB drive, moves 6,500 WMV files over to the "videos" folder. Then it's suppose to create an HTML page with hyperlinks to each file. Here is my current example that's broken. I'm trying to have it crawl the videos directory and create an HTML page with hyper...
1
2009-11-17T15:45:13Z
1,749,860
<pre><code>def createHTML(): h = open("videos.html", 'w') for vid in os.listdir: path = "./videos" + vid f = open(path, r) h.write("&lt;a href='"+f.name+"'&gt;"+f.name[f.name.rfind('\\') +1 :]+"&lt;/a&gt;") f.close() h.close() print "done writing HTML file" </code></pre>
0
2009-11-17T15:59:52Z
[ "python" ]
Stackless Python and PyQt
1,749,818
<p>What experiences do you have with Stackless Python and PyQt?</p> <p>Issues i would be happy if people address:</p> <ol> <li><p>Compilation of PyQt for Stackless: does PyQt need to be compiled especially for Stackless? is the compilation smooth? problems with bindings etc.</p></li> <li><p>Stability: any unexpected ...
4
2009-11-17T15:52:58Z
2,001,364
<p><strong>If you're interested in all that because of speed optimization:</strong></p> <p>You may want to check out <a href="http://code.google.com/p/unladen-swallow/" rel="nofollow"><strong>Unladen Swallow</strong></a> ( <a href="http://en.wikipedia.org/wiki/Unladen_Swallow" rel="nofollow">Wikipedia here</a> ). Goog...
0
2010-01-04T18:48:29Z
[ "python", "pyqt", "pyqt4", "stackless", "python-stackless" ]
Stackless Python and PyQt
1,749,818
<p>What experiences do you have with Stackless Python and PyQt?</p> <p>Issues i would be happy if people address:</p> <ol> <li><p>Compilation of PyQt for Stackless: does PyQt need to be compiled especially for Stackless? is the compilation smooth? problems with bindings etc.</p></li> <li><p>Stability: any unexpected ...
4
2009-11-17T15:52:58Z
2,047,183
<p>I tried to go down this path several months ago and decided it was not worth the effort.</p> <p>I was able to run a binary install of PyQt (on Windows) against a stackless version of Python, but I found that I had to manually go in and change some of the files. I was getting an error message (sorry, I forget what ...
0
2010-01-12T06:40:11Z
[ "python", "pyqt", "pyqt4", "stackless", "python-stackless" ]
replace or remove one null (python)
1,749,827
<p>I would like to remove one null byte in a string, and sometime replace it with another char. Like that :</p> <p>string = "41 00 36 00 36 00 00 00 57 00 46 00 42 00 41 00 61 00 62 00 73 00 20 00 36 00"</p> <p>i was thinking about using random and replace, but replace always start by the first one:</p> <pre><code>r...
0
2009-11-17T15:54:22Z
1,749,891
<p>Ugly code tested in Python 3.1.1</p> <pre><code>import random s = "a00b00c00d00e00f00g" s1 = s.split("00") i = random.randint(1,s.count("00")) s2 = "00".join(s1[:i]) s3 = "00".join(s1[i:]) print (s2+"EE"+s3) </code></pre>
1
2009-11-17T16:04:50Z
[ "python", "random", "replace" ]
replace or remove one null (python)
1,749,827
<p>I would like to remove one null byte in a string, and sometime replace it with another char. Like that :</p> <p>string = "41 00 36 00 36 00 00 00 57 00 46 00 42 00 41 00 61 00 62 00 73 00 20 00 36 00"</p> <p>i was thinking about using random and replace, but replace always start by the first one:</p> <pre><code>r...
0
2009-11-17T15:54:22Z
1,749,919
<p>Not only that, but <code>00</code> isn't "a null" by any stretch of the imagination -- it's a 2-characters string. You appear to silently assume that your string is made up of substrings each of two hex digits, and any string operation you perform will have no idea about this little private convention of yours -- i...
7
2009-11-17T16:09:11Z
[ "python", "random", "replace" ]
replace or remove one null (python)
1,749,827
<p>I would like to remove one null byte in a string, and sometime replace it with another char. Like that :</p> <p>string = "41 00 36 00 36 00 00 00 57 00 46 00 42 00 41 00 61 00 62 00 73 00 20 00 36 00"</p> <p>i was thinking about using random and replace, but replace always start by the first one:</p> <pre><code>r...
0
2009-11-17T15:54:22Z
1,749,991
<p>This solution grabs all possible locations of "00" for even values of the string and chooses one at random. It should solve your problem:</p> <pre><code>from random import choice string = "4100360036000000570046004200410061006200730020003600" zeroes = [] for i, s in enumerate(string): if i % 2 == 0 and i &lt...
0
2009-11-17T16:18:25Z
[ "python", "random", "replace" ]
replace or remove one null (python)
1,749,827
<p>I would like to remove one null byte in a string, and sometime replace it with another char. Like that :</p> <p>string = "41 00 36 00 36 00 00 00 57 00 46 00 42 00 41 00 61 00 62 00 73 00 20 00 36 00"</p> <p>i was thinking about using random and replace, but replace always start by the first one:</p> <pre><code>r...
0
2009-11-17T15:54:22Z
1,750,149
<p>You cannot replace bytes in a string. Instead, you want to use an array for this.</p> <pre><code>import array s = "4100360036000000570046004200410061006200730020003600" a = array.array('c',s) b = array.array('c',"B") # make a one character array containing B print a a[6] = b[0] print b </code></pre> <p>Of course, ...
0
2009-11-17T16:41:22Z
[ "python", "random", "replace" ]
Replacement for python statvfs?
1,749,928
<p>The <a href="http://docs.python.org/library/statvfs.html" rel="nofollow">python statvfs module</a> was marked as deprecated since python 2.6 and it's now removed since python 3.0. I haven't been able to figure out what apps are supposed to use if they want to get information about a disk, specifically how to check t...
6
2009-11-17T16:10:25Z
1,749,950
<p>It appears that only the module that contains the constants for sequential access is being deprecated. </p> <p>Doing</p> <pre><code>x = os.statvfs('/') x.f_favail </code></pre> <p>will still work.</p> <p>Sidenote: according to the docs, this function is only available on unix based platforms. So OSX and linux va...
7
2009-11-17T16:13:31Z
[ "python" ]
Replacement for python statvfs?
1,749,928
<p>The <a href="http://docs.python.org/library/statvfs.html" rel="nofollow">python statvfs module</a> was marked as deprecated since python 2.6 and it's now removed since python 3.0. I haven't been able to figure out what apps are supposed to use if they want to get information about a disk, specifically how to check t...
6
2009-11-17T16:10:25Z
35,790,284
<p>I had the same question, it's <a href="https://docs.python.org/3/library/os.html?highlight=fstatvfs#os.fstatvfs" rel="nofollow">os.fstatvfs(fd)</a></p> <blockquote> <p>As of Python 3.3, this is equivalent to os.statvfs(fd). Availability: Unix.</p> </blockquote>
1
2016-03-04T07:23:28Z
[ "python" ]
Weird PyPI authentication behavior
1,750,186
<p>I'm trying to upload my package to PyPI. It asks me to identify, I do, it gives an OK response (which doesn't happen unless the identification is right), but then it claims I didn't identify! Why?</p> <pre><code>[...] removing 'build\bdist.win32\egg' (and everything under it) running register We need to know who yo...
1
2009-11-17T16:47:03Z
1,752,920
<p>I've never encountered that myself, but some things to check:</p> <ol> <li>Make sure you can login to PyPI using your browser with the username and password.</li> <li>Check that ~/.pypirc has the correct contents. If it does not exist, try creating it.</li> <li>Check your setup.cfg file to make sure all the PyPI se...
1
2009-11-18T00:50:16Z
[ "python", "distribution", "distutils", "pypi" ]
Weird PyPI authentication behavior
1,750,186
<p>I'm trying to upload my package to PyPI. It asks me to identify, I do, it gives an OK response (which doesn't happen unless the identification is right), but then it claims I didn't identify! Why?</p> <pre><code>[...] removing 'build\bdist.win32\egg' (and everything under it) running register We need to know who yo...
1
2009-11-17T16:47:03Z
4,090,759
<p>You were using an old version of Python (and Distutils as a result). This bug was fixed in r68415 2009-01-09 by Tarek Ziade. Try to upload with any Python 2.x version released afterwards.</p>
1
2010-11-03T19:16:12Z
[ "python", "distribution", "distutils", "pypi" ]
Fractal image scaling with Python
1,750,290
<p>I am in a position where <strong>relatively low resolution</strong> images are provided (via an API, higher resolution images are not available) and <strong>high resolution</strong> images need to be generated.</p> <p>I've taken a look at <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> and ...
4
2009-11-17T17:02:45Z
1,750,331
<p>There are algorithms, and you're definitely not going to find them in Python. To start with, you can take this paper:</p> <p>Daniel Glasner, Shai Bagon, and Michal Irani, "Super-Resolution from a Single Image," in Proceedings of the IEEE International Conference on Computer Vision, Kyoto, Japan, 2009.</p> <p>It is...
9
2009-11-17T17:09:27Z
[ "python", "image-processing", "python-imaging-library", "fractals" ]
Fractal image scaling with Python
1,750,290
<p>I am in a position where <strong>relatively low resolution</strong> images are provided (via an API, higher resolution images are not available) and <strong>high resolution</strong> images need to be generated.</p> <p>I've taken a look at <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> and ...
4
2009-11-17T17:02:45Z
1,750,953
<p>Fractal-based image scaling is still quite unusual and hasn't settled down onto one accepted-best algorithm yet. I'm afraid you aren't going to find it in standard image processing libraries yet.</p> <p>It's also not invariably preferable to bicubic. It can have artefacts which will be undesirable for some kinds of...
2
2009-11-17T18:48:42Z
[ "python", "image-processing", "python-imaging-library", "fractals" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,381
<p>With infinite memory, you can hash every 1k string along with its position in the 1 GB file.</p> <p>With less than infinite memory, you will be bounded by how many memory pages you touch when searching.</p>
0
2009-11-17T17:18:54Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,386
<p>There are a number of string matching algorithms use in the field of genetics to find substrings. You might try <a href="http://cat.inist.fr/?aModele=afficheN&amp;cpsidt=13397373" rel="nofollow">this paper</a> or <a href="http://www.springerlink.com/content/3g5316143gr25124/" rel="nofollow">this paper</a></p>
5
2009-11-17T17:19:38Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,414
<p>Are you willing to spend a significant time preprocessing the string?</p> <p>If you are, what you can do is build a list of n-grams with offsets.</p> <p>Suppose your alphabet is hex bytes and you are using 1-grams. </p> <p>Then for 00-ff, you can create a dictionary that looks like this(perlese, sorry)</p> <pre>...
1
2009-11-17T17:23:04Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,446
<p>I don't know definitively if the <code>find()</code> method for strings is faster than the <code>search()</code> method provided by Python's <code>re</code> (regular expressions) module, but there's only one way to find out.</p> <p>If you're just searching a string, what you want is this:</p> <pre><code>import re ...
0
2009-11-17T17:28:52Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,457
<p><a href="http://www.youtube.com/watch?v=V5hZoJ6uK-s" rel="nofollow">http://www.youtube.com/watch?v=V5hZoJ6uK-s</a> Will be of most value to you. Its an MIT lecture on Dynamic Programming</p>
0
2009-11-17T17:30:12Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,531
<p>As far as I know, standard find algorithm is naive algorithm with complexity about n*m comparisons, because it checks patterns against every possible offset. There are some more effective algoithms, requiring about n+m comparisons. If your string is not a natural language string, you can try <a href="http://en.wiki...
1
2009-11-17T17:41:25Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,708
<p>If the patterns are fairly random, you can precompute the location of n-prefixes of strings.</p> <p>Instead of going over all options for n-prefixes, just use the actual ones in the 1GB string - there will be less than 1Gig of those. Use as big a prefix as fits in your memory, I don't have 16GB RAM to check but a p...
0
2009-11-17T18:07:16Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,774
<p>As you clarify that long-ish preprocessing is acceptable, I'd suggest a variant of <a href="http://en.wikipedia.org/wiki/Rabin-karp" rel="nofollow">Rabin-Karp</a>: "an algorithm of choice for multiple pattern search", as wikipedia puts it.</p> <p>Define a "rolling hash" function, i.e., one such that, when you know ...
11
2009-11-17T18:19:04Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,750,895
<p>Someone hinted at a possible way to index this thing if you have abundant RAM (or possibly even disk/swap) available.</p> <p>Imagine if you performed a simple 32-bit CRC on a 1K block extending from each character in the original Gig string. This would result in 4bytes of checksum data for each byte offset from th...
0
2009-11-17T18:39:26Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Fastest way to search 1GB+ a string of data for the first occurence of a pattern in Python
1,750,343
<p>There's a 1 Gigabyte string of arbitrary data which you can assume to be equivalent to something like:</p> <pre><code>1_gb_string=os.urandom(1*gigabyte) </code></pre> <p>We will be searching this string, <code>1_gb_string</code>, for an infinite number of fixed width, 1 kilobyte patterns, <code>1_kb_pattern</code>...
12
2009-11-17T17:11:40Z
1,762,275
<p>One efficient but complex way is <a href="http://www.ddj.com/architect/184405504" rel="nofollow">full-text indexing with the Burrows-Wheeler transform</a>. It involves performing a BWT on your source text, then using a small index on that to quickly find any substring in the text that matches your input pattern.</p>...
0
2009-11-19T10:19:50Z
[ "python", "algorithm", "search", "large-data-volumes" ]
Jython 2.1 __getattr__
1,750,392
<p>I am trying to implement a wrapper/proxy class for a java object (baseClient) in jython v2.1. Everything seems to be working ok except when the following statement is encountered:</p> <pre><code>if __client != None # __client is an instance of the ClientProxy class </code></pre> <p><code>raise AttributeError(attr)...
0
2009-11-17T17:20:03Z
1,750,813
<pre><code>if __client != None: </code></pre> <p>For testing against specific instances such as None, it's idiomatic to use the identity operator:</p> <pre><code>if __client is not None: </code></pre> <p>This will avoid the problem of calling comparators.</p> <p>However, the fact that <code>__getattr__</code> raise...
0
2009-11-17T18:26:30Z
[ "python", "jython", "wrapping", "setattr", "getattr" ]
use random functions (python)
1,750,480
<p>I wonder if we can do that in python, let's suppose we have 3 differents functions to processing datas like this:</p> <pre><code>def main(): def process(data): ..... def process1(data): ..... def process2(data): ..... def run(): test = choice([process,process1,process2]) test(data)...
2
2009-11-17T17:33:33Z
1,750,502
<p>Sure is!</p> <p>That the nice thing in Python, functions are first class objects and can be referenced in such an easy fashion.</p> <p>The implication is that all three methods have the same expectation with regards to arguments passed to them. (This probably goes without saying).</p>
3
2009-11-17T17:36:26Z
[ "python", "function", "random" ]
use random functions (python)
1,750,480
<p>I wonder if we can do that in python, let's suppose we have 3 differents functions to processing datas like this:</p> <pre><code>def main(): def process(data): ..... def process1(data): ..... def process2(data): ..... def run(): test = choice([process,process1,process2]) test(data)...
2
2009-11-17T17:33:33Z
1,750,603
<p>Just use the random number module in python.</p> <pre><code>random.choice(seq) </code></pre> <p>This will give you a random item from the sequence.</p> <p><a href="http://docs.python.org/library/random.html" rel="nofollow">http://docs.python.org/library/random.html</a></p>
1
2009-11-17T17:51:05Z
[ "python", "function", "random" ]
use random functions (python)
1,750,480
<p>I wonder if we can do that in python, let's suppose we have 3 differents functions to processing datas like this:</p> <pre><code>def main(): def process(data): ..... def process1(data): ..... def process2(data): ..... def run(): test = choice([process,process1,process2]) test(data)...
2
2009-11-17T17:33:33Z
1,750,612
<p>Your code will work just like you wrote it, if you add this to the top:</p> <pre><code>from random import choice </code></pre> <p>Or, I think it would be slightly better to rewrite your code like so:</p> <pre><code>import random def main(): def process(data): ..... def process1(data): ..... def p...
0
2009-11-17T17:52:21Z
[ "python", "function", "random" ]
use random functions (python)
1,750,480
<p>I wonder if we can do that in python, let's suppose we have 3 differents functions to processing datas like this:</p> <pre><code>def main(): def process(data): ..... def process1(data): ..... def process2(data): ..... def run(): test = choice([process,process1,process2]) test(data)...
2
2009-11-17T17:33:33Z
1,750,616
<p>Excellent approach (net of some oversimplification in your skeleton code). Since you ask for an example:</p> <pre><code>import random def main(): def process(data): return data + [0] def process1(data): return data + [9] def process2(data): return data + [7] def run(data): test = rando...
3
2009-11-17T17:52:59Z
[ "python", "function", "random" ]
Import C++ classes in python?
1,750,517
<p>so.. let's say i have this C function:</p> <pre><code>PyObject* Foo(PyObject* pSelf, PyObject* pArgs) { MessageBox(NULL, "Foo was called!", "Info", MB_OK); return PyInt_FromLong(0); } </code></pre> <p>and then, I have to do this:</p> <pre><code>static PyMethodDef Methods[] = { {"Foo", Foo, METH_NOARG...
0
2009-11-17T17:39:56Z
1,750,542
<p>Take a look at <a href="http://www.boost.org/doc/libs/1%5F40%5F0/libs/python/doc/tutorial/doc/html/python/exposing.html" rel="nofollow">boost python</a> page. Search for 'free function'.</p>
1
2009-11-17T17:43:00Z
[ "c++", "python" ]
Import C++ classes in python?
1,750,517
<p>so.. let's say i have this C function:</p> <pre><code>PyObject* Foo(PyObject* pSelf, PyObject* pArgs) { MessageBox(NULL, "Foo was called!", "Info", MB_OK); return PyInt_FromLong(0); } </code></pre> <p>and then, I have to do this:</p> <pre><code>static PyMethodDef Methods[] = { {"Foo", Foo, METH_NOARG...
0
2009-11-17T17:39:56Z
1,750,549
<p><a href="http://www.boost.org/doc/libs/release/libs/python/doc/" rel="nofollow">boost.python</a> enables you to do that very effectively.</p>
5
2009-11-17T17:43:49Z
[ "c++", "python" ]
Import C++ classes in python?
1,750,517
<p>so.. let's say i have this C function:</p> <pre><code>PyObject* Foo(PyObject* pSelf, PyObject* pArgs) { MessageBox(NULL, "Foo was called!", "Info", MB_OK); return PyInt_FromLong(0); } </code></pre> <p>and then, I have to do this:</p> <pre><code>static PyMethodDef Methods[] = { {"Foo", Foo, METH_NOARG...
0
2009-11-17T17:39:56Z
1,750,631
<p><a href="http://www.swig.org/Doc1.3/Python.html" rel="nofollow">SWIG</a> would work pretty well, too.</p>
2
2009-11-17T17:54:13Z
[ "c++", "python" ]
Import C++ classes in python?
1,750,517
<p>so.. let's say i have this C function:</p> <pre><code>PyObject* Foo(PyObject* pSelf, PyObject* pArgs) { MessageBox(NULL, "Foo was called!", "Info", MB_OK); return PyInt_FromLong(0); } </code></pre> <p>and then, I have to do this:</p> <pre><code>static PyMethodDef Methods[] = { {"Foo", Foo, METH_NOARG...
0
2009-11-17T17:39:56Z
1,753,461
<p>Cython has the best <a href="http://docs.cython.org/src/userguide/wrapping%5FCPlusPlus.html" rel="nofollow">C++ wrapping</a> I have found, even though it is a bit more verbose than SWIG and it is a bit of a mindset to get into. It's easier to write mappings than SWIG -- because it uses Python types -- but you have ...
0
2009-11-18T03:32:25Z
[ "c++", "python" ]
How to use Python to calculate time
1,750,644
<p>I want to write python script that acts as a time calculator.</p> <p>For example:</p> <p>Suppose the time is now 13:05:00</p> <p>I want to add 1 hour, 23 minutes, and 10 seconds to it.</p> <p>and I want to print the answer out. </p> <p>How do I do this in Python?</p> <p>What if date is also involved?</p>
4
2009-11-17T17:55:43Z
1,750,656
<p>Look at <code>mx.DateTime</code>, and <code>DateTimeDelta</code> in particular.</p> <pre><code>import mx.DateTime d = mx.DateTime.DateTimeDelta(0, 1, 23, 10) x = mx.DateTime.now() + d x.strftime() </code></pre> <p>Keep in mind that time is actually a rather complicated thing to work with. Leap years and leap seco...
0
2009-11-17T17:58:41Z
[ "python", "datetime", "time" ]
How to use Python to calculate time
1,750,644
<p>I want to write python script that acts as a time calculator.</p> <p>For example:</p> <p>Suppose the time is now 13:05:00</p> <p>I want to add 1 hour, 23 minutes, and 10 seconds to it.</p> <p>and I want to print the answer out. </p> <p>How do I do this in Python?</p> <p>What if date is also involved?</p>
4
2009-11-17T17:55:43Z
1,750,664
<p>Look into <a href="http://docs.python.org/library/datetime.html#datetime.timedelta" rel="nofollow">datetime.timedelta</a>.</p> <pre><code>Example &gt;&gt;&gt; from datetime import timedelta &gt;&gt;&gt; year = timedelta(days=365) &gt;&gt;&gt; another_year = timedelta(weeks=40, days=84, hours=23, ... ...
3
2009-11-17T17:59:17Z
[ "python", "datetime", "time" ]
How to use Python to calculate time
1,750,644
<p>I want to write python script that acts as a time calculator.</p> <p>For example:</p> <p>Suppose the time is now 13:05:00</p> <p>I want to add 1 hour, 23 minutes, and 10 seconds to it.</p> <p>and I want to print the answer out. </p> <p>How do I do this in Python?</p> <p>What if date is also involved?</p>
4
2009-11-17T17:55:43Z
1,750,669
<p>The datetime class in python will provide everything you need. It supports addition, subtraction and many other operations.</p> <p><a href="http://docs.python.org/library/datetime.html" rel="nofollow">http://docs.python.org/library/datetime.html</a></p>
0
2009-11-17T17:59:54Z
[ "python", "datetime", "time" ]
How to use Python to calculate time
1,750,644
<p>I want to write python script that acts as a time calculator.</p> <p>For example:</p> <p>Suppose the time is now 13:05:00</p> <p>I want to add 1 hour, 23 minutes, and 10 seconds to it.</p> <p>and I want to print the answer out. </p> <p>How do I do this in Python?</p> <p>What if date is also involved?</p>
4
2009-11-17T17:55:43Z
1,750,682
<p><a href="http://docs.python.org/library/datetime.html#datetime.timedelta" rel="nofollow"><code>datetime.timedelta</code></a> is designed for fixed time differences (e.g. 1 day is fixed, 1 month is not).</p> <pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; t = datetime.time(13, 5) &gt;&gt;&gt; print t 13:05:00 &...
5
2009-11-17T18:01:52Z
[ "python", "datetime", "time" ]
Django development server CPU intensive - how to analyse?
1,750,676
<p>I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this?</p> <p>Thanks!...
4
2009-11-17T18:01:16Z
1,750,793
<p>Hit Control-C and crash the process. It will probably crash somewhere that it's spending a lot of time.</p> <p>Or you could use a profiler. </p>
3
2009-11-17T18:22:53Z
[ "python", "django", "cpu" ]
Django development server CPU intensive - how to analyse?
1,750,676
<p>I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this?</p> <p>Thanks!...
4
2009-11-17T18:01:16Z
1,751,800
<p><a href="http://docs.python.org/library/profile.html" rel="nofollow">http://docs.python.org/library/profile.html</a></p> <p>That's the standard approach.</p>
2
2009-11-17T21:08:24Z
[ "python", "django", "cpu" ]
Django development server CPU intensive - how to analyse?
1,750,676
<p>I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this?</p> <p>Thanks!...
4
2009-11-17T18:01:16Z
1,753,604
<p>The standard approach is to use a profiler. If, for some reason you can't (such as there is no profiler available in the Apache modpython that is running your Django) your best bet might be simply to instrument your program with logging. Watch the messages from your program, and see what you can learn from them.</...
0
2009-11-18T04:17:42Z
[ "python", "django", "cpu" ]
Django development server CPU intensive - how to analyse?
1,750,676
<p>I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this?</p> <p>Thanks!...
4
2009-11-17T18:01:16Z
1,756,874
<p>FWIW, you should do the profiling, but when you do I'll bet you find that the answer is "polling for changes to your files so it can auto-reload." You might do a quick test with "python manage.py runserver --noreload" and see how that affects the CPU usage.</p>
9
2009-11-18T15:41:32Z
[ "python", "django", "cpu" ]
Restarting a self-updating python script
1,750,757
<p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p> <p>I am not sure what the best way to restart the script after it has been updated.</p> <p>Any ideas?</p> <p>I don't really want to have a separate update script. oh an...
24
2009-11-17T18:16:55Z
1,750,795
<p>The pocoo team have a very good reloader for their development server inside of werkzueg. Check the code out <a href="https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/serving.py" rel="nofollow">here</a> (it's towards the bottom of the file).</p>
1
2009-11-17T18:23:16Z
[ "python", "auto-update" ]
Restarting a self-updating python script
1,750,757
<p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p> <p>I am not sure what the best way to restart the script after it has been updated.</p> <p>Any ideas?</p> <p>I don't really want to have a separate update script. oh an...
24
2009-11-17T18:16:55Z
1,750,797
<p>In Linux, or any other form of unix, <a href="http://docs.python.org/library/os.html?highlight=os.exec#os.execl">os.execl</a> and friends are a good choice for this -- you just need to re-exec <a href="http://docs.python.org/library/sys.html?highlight=sys.executable#sys.executable">sys.executable</a> with the same p...
20
2009-11-17T18:23:27Z
[ "python", "auto-update" ]