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
listlengths
1
5
Interface for modifying Windows environment variables from Python
1,085,852
<p>How can I persistently modify the Windows environment variables from a Python script? (it's the setup.py script)</p> <p>I'm looking for a standard function or module to use for this. I'm already familiar with the <a href="http://code.activestate.com/recipes/416087/">registry way of doing it</a>, but any comments re...
15
2009-07-06T07:48:40Z
1,085,879
<p>The registry way is if you want to modify it permanently for everything, which I guess is what you want here since it's in setup.py.</p> <p>Temporarily for just your process, then os.environ is the trick.</p>
1
2009-07-06T07:59:19Z
[ "python", "windows", "environment-variables" ]
Interface for modifying Windows environment variables from Python
1,085,852
<p>How can I persistently modify the Windows environment variables from a Python script? (it's the setup.py script)</p> <p>I'm looking for a standard function or module to use for this. I'm already familiar with the <a href="http://code.activestate.com/recipes/416087/">registry way of doing it</a>, but any comments re...
15
2009-07-06T07:48:40Z
1,085,950
<p>In the os module, there is getenv and putenv functions. However, it seems that the putenv is not working correctly and that you must use the windows registry instead</p> <p>Look at <a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/60a59bbf8207aeb0/4e9e51c84dc7a01f" rel="nofollow"> this d...
1
2009-07-06T08:18:44Z
[ "python", "windows", "environment-variables" ]
Interface for modifying Windows environment variables from Python
1,085,852
<p>How can I persistently modify the Windows environment variables from a Python script? (it's the setup.py script)</p> <p>I'm looking for a standard function or module to use for this. I'm already familiar with the <a href="http://code.activestate.com/recipes/416087/">registry way of doing it</a>, but any comments re...
15
2009-07-06T07:48:40Z
1,086,098
<p>It may be just as easy to use the external Windows <code>setx</code> command:</p> <pre><code>C:\&gt;set NEWVAR Environment variable NEWVAR not defined C:\&gt;python Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more inform...
4
2009-07-06T08:59:42Z
[ "python", "windows", "environment-variables" ]
Interface for modifying Windows environment variables from Python
1,085,852
<p>How can I persistently modify the Windows environment variables from a Python script? (it's the setup.py script)</p> <p>I'm looking for a standard function or module to use for this. I'm already familiar with the <a href="http://code.activestate.com/recipes/416087/">registry way of doing it</a>, but any comments re...
15
2009-07-06T07:48:40Z
1,146,404
<p>Using setx has few drawbacks, especially if you're trying to append to environment variables (eg. setx PATH %Path%;C:\mypath) This will repeatedly append to the path every time you run it, which can be a problem. Worse, it doesn't distinguish between the machine path (stored in HKEY_LOCAL_MACHINE), and the user path...
17
2009-07-18T01:25:12Z
[ "python", "windows", "environment-variables" ]
Interface for modifying Windows environment variables from Python
1,085,852
<p>How can I persistently modify the Windows environment variables from a Python script? (it's the setup.py script)</p> <p>I'm looking for a standard function or module to use for this. I'm already familiar with the <a href="http://code.activestate.com/recipes/416087/">registry way of doing it</a>, but any comments re...
15
2009-07-06T07:48:40Z
1,179,789
<p>It must have been a millennium ago that I've tried to change the environment of the current DOS session by means of a program. The problem is: that program runs within its own DOS shell, so it has to operate on its parent environment. It takes a walk, starting at the DOS Info Block, all along the chain of Memory Con...
3
2009-07-24T19:45:07Z
[ "python", "windows", "environment-variables" ]
Interface for modifying Windows environment variables from Python
1,085,852
<p>How can I persistently modify the Windows environment variables from a Python script? (it's the setup.py script)</p> <p>I'm looking for a standard function or module to use for this. I'm already familiar with the <a href="http://code.activestate.com/recipes/416087/">registry way of doing it</a>, but any comments re...
15
2009-07-06T07:48:40Z
28,439,472
<p>This Python-script[*] attempts to modify the GLOBAL env-vars in registry, if no-permissions falls-back to user's registry, and then notifies all windows about the change:</p> <pre class="lang-py prettyprint-override"><code>""" Show/Modify/Append registry env-vars (ie `PATH`) and notify Windows-applications to picku...
0
2015-02-10T18:50:23Z
[ "python", "windows", "environment-variables" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,085,929
<p>As you've identified, using a JVM doesn't restrict you to using the Java language. A list of JVM languages and links can be found <a href="http://en.wikipedia.org/wiki/List%5Fof%5FJVM%5Flanguages" rel="nofollow">here</a>. <em>However</em>, the Google App Engine does restrict the set of classes you can use from the n...
6
2009-07-06T08:13:08Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,086,259
<p>Based on experience with running these VMs on other platforms, I'd say that you'll probably get more raw performance out of Java than Python. Don't underestimate Python's selling points, however: The Python language is much more productive in terms of lines of code - the general agreement is that Python requires a ...
16
2009-07-06T09:48:32Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,087,878
<p>I'm biased (being a Python expert but pretty rusty in Java) but I think the Python runtime of GAE is currently more advanced and better developed than the Java runtime -- the former has had one extra year to develop and mature, after all.</p> <p>How things will proceed going forward is of course hard to predict -- ...
113
2009-07-06T16:17:10Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,093,160
<p>I'm strongly recommending Java for GAE and here's why:</p> <ol> <li>Performance: Java is potentially faster then Python.</li> <li>Python development is under pressure of a lack of third-party libraries. For example, there is no XSLT for Python/GAE at all. Almost all Python libraries are C bindings (and those are un...
5
2009-07-07T15:50:45Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,337,632
<p>There's also project <a href="http://code.google.com/p/unladen-swallow/wiki/ProjectPlan" rel="nofollow">Unladen Swallow</a>, which is apparently Google-funded if not Google-owned. They're trying to implement a LLVM-based backend for Python 2.6.1 bytecode, so they can use a JIT and various nice native code/GC/multi-c...
2
2009-08-26T21:36:11Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,442,628
<p>Gone with Python even though GWT seems a perfect match for the kind of an app I'm developing. JPA is pretty messed up on GAE (e.g. no @Embeddable and other obscure non-documented limitations). Having spent a week, I can tell that Java just doesn't feel right on GAE at the moment.</p>
1
2009-09-18T04:40:43Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
1,464,516
<p>Watch this app for changes in Python and Java performance:</p> <p><a href="http://gaejava.appspot.com/">http://gaejava.appspot.com/</a></p> <p>Currently, Python and using the low-level API in Java are faster than JDO on Java, <strong>for this simple test</strong>. At least if the underlying engine changes, that ap...
66
2009-09-23T07:45:21Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
2,636,174
<p>The beauty of python nowdays is how well it communicates with other languages. For instance you can have both python and java on the same table with Jython. Of course jython even though it fully supports java libraries it does not support fully python libraries. But its an ideal solution if you want to mess with Jav...
2
2010-04-14T09:14:37Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
2,638,859
<p>An important question to consider in deciding between Python and Java is <strong>how you will use the datastore in each language</strong> (and most other angles to the original question have already been covered quite well in this topic).</p> <p><strong>For Java</strong>, the standard method is to use JDO or JPA. ...
9
2010-04-14T15:44:29Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
2,680,204
<p>It's a good question, and I think many of the responses have given good view points of pros and cons on both sides of the fence. I've tried both Python and JVM-based AppEngine (in my case I was using <a href="http://gaelyk.appspot.com/" rel="nofollow">Gaelyk</a> which is a Groovy application framework built for App...
3
2010-04-21T03:54:05Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
2,979,149
<p>Based on how much I hear Java people complain about AppEngine compared to Python users, I would say Python is much less stressful to use.</p>
3
2010-06-05T04:24:36Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
3,393,601
<p>I've been amazed at how clean, straightforward, and problem free the Python/Django SDK is. However I started running into situations where I needed to start doing more JavaScript and thought I might want to take advantage of the GWT and other Java utilities. I've gotten just half way through the GAE Java tutorial,...
6
2010-08-03T04:37:36Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
5,096,947
<p>One think to take into account are the frameworks you intend yo use. Not all frameworks on Java side are well suited for applications running on App Engine, which is somewhat different than traditional Java app servers. </p> <p>One thing to consider is the application startup time. With traditional Java web apps yo...
1
2011-02-23T20:51:34Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
18,255,495
<p><strong>June 2013:</strong> This video is a very good answer by a google engineer:</p> <p><a href="http://www.youtube.com/watch?v=tLriM2krw2E">http://www.youtube.com/watch?v=tLriM2krw2E</a></p> <p>TLDR; is: </p> <ul> <li>Pick the language that you and your team is most productive with</li> <li>If you want to buil...
11
2013-08-15T15:00:01Z
[ "java", "python", "google-app-engine" ]
Choosing Java vs Python on Google App Engine
1,085,898
<p>Currently Google App Engine supports both Python &amp; Java. Java support is less mature. However, Java seems to have a longer list of libraries and especially support for Java bytecode regardless of the languages used to write that code. Which language will give better performance and more power? Please advise. Tha...
147
2009-07-06T08:05:58Z
25,894,549
<p>I'm a little late to the conversation, but here are my two cents. I really had a hard time choosing between Python and Java, since I am well versed in both languages. As we all know, there are advantages and disadvantages for both, and you have to take in account your requirements and the frameworks that work best f...
5
2014-09-17T15:24:57Z
[ "java", "python", "google-app-engine" ]
where to start OpenID implementation in python,which API is better suits
1,086,127
<p>im using python API in our research project.i read lot of ppt and material, and finally understand this concept now i have task to execute simple function which is chek user credential thorough openid provider and return successful after the valid user check.....</p>
-1
2009-07-06T09:07:45Z
1,086,150
<p>Why not use <a href="http://openidenabled.com/python-openid/" rel="nofollow">Python OpenID</a> library?</p>
2
2009-07-06T09:13:27Z
[ "python" ]
where to start OpenID implementation in python,which API is better suits
1,086,127
<p>im using python API in our research project.i read lot of ppt and material, and finally understand this concept now i have task to execute simple function which is chek user credential thorough openid provider and return successful after the valid user check.....</p>
-1
2009-07-06T09:07:45Z
1,086,227
<p>To add to the recommendation of the Python OpenID library: their docs pages for the <a href="http://openidenabled.com/files/python-openid/docs/2.2.4/openid.server.server-module.html" rel="nofollow">server</a> and <a href="http://openidenabled.com/files/python-openid/docs/2.2.4/openid.consumer.consumer-module.html" r...
3
2009-07-06T09:37:20Z
[ "python" ]
Is is possible to return an object or value from a Python script to the hosting application?
1,086,188
<p>For example in Lua you can place the following line at the end of a script:</p> <pre><code>return &lt;some-value/object&gt; </code></pre> <p>The value/object that is returned can then be retrieved by the hosting application.</p> <p>I use this pattern so that scripts can represent factories for event handlers. Th...
2
2009-07-06T09:23:41Z
1,086,209
<p>It's totally possible and a common technique when embedding Python. <a href="http://www.linuxjournal.com/article/8497" rel="nofollow">This article</a> shows the basics, as does <a href="http://python.active-venture.com/ext/pure-embedding.html" rel="nofollow">this page</a>. The core function is <code>PyObject_CallObj...
2
2009-07-06T09:29:59Z
[ "c#", "python", "ironpython" ]
Is is possible to return an object or value from a Python script to the hosting application?
1,086,188
<p>For example in Lua you can place the following line at the end of a script:</p> <pre><code>return &lt;some-value/object&gt; </code></pre> <p>The value/object that is returned can then be retrieved by the hosting application.</p> <p>I use this pattern so that scripts can represent factories for event handlers. Th...
2
2009-07-06T09:23:41Z
1,086,213
<p>This can be done in Python just the same way. You can require the plugin to provide a getHandler() function / method that returns the event handler:</p> <pre><code>class myPlugin(object): def doIt(self,event,*args): print "Doing important stuff" def getHandler(self,document): print "Initializing plugi...
3
2009-07-06T09:30:59Z
[ "c#", "python", "ironpython" ]
Is is possible to return an object or value from a Python script to the hosting application?
1,086,188
<p>For example in Lua you can place the following line at the end of a script:</p> <pre><code>return &lt;some-value/object&gt; </code></pre> <p>The value/object that is returned can then be retrieved by the hosting application.</p> <p>I use this pattern so that scripts can represent factories for event handlers. Th...
2
2009-07-06T09:23:41Z
1,086,219
<p>The way I would do it (and the way I've seen it done) is have a function for each event all packed into one module (or across several, doesn't matter), and then call the function through C/C++/C# and use its return value.</p>
1
2009-07-06T09:33:27Z
[ "c#", "python", "ironpython" ]
Is is possible to return an object or value from a Python script to the hosting application?
1,086,188
<p>For example in Lua you can place the following line at the end of a script:</p> <pre><code>return &lt;some-value/object&gt; </code></pre> <p>The value/object that is returned can then be retrieved by the hosting application.</p> <p>I use this pattern so that scripts can represent factories for event handlers. Th...
2
2009-07-06T09:23:41Z
1,086,244
<p>See some examples in <a href="http://www.voidspace.org.uk/ironpython/hosting%5Fapi.shtml" rel="nofollow">Embedding the Dynamic Language Runtime</a>.</p> <p>A simple example, <a href="http://www.voidspace.org.uk/ironpython/hosting%5Fapi.shtml#setting-and-fetching-variables" rel="nofollow">setting-and-fetching-variab...
2
2009-07-06T09:45:15Z
[ "c#", "python", "ironpython" ]
Parsing HTML rows into CSV
1,086,266
<p>First off the html row looks like this: </p> <pre><code>&lt;tr class="evenColor"&gt; blahblah TheTextIneed blahblah and ends with &lt;/tr&gt; </code></pre> <p>I would show the real html but I am sorry to say don't know how to block it. <em>feels shame</em></p> <p>Using BeautifulSoup (Python) or any other recommen...
1
2009-07-06T09:50:25Z
1,086,311
<p>That looks fine, and BeautifulSoup is useful for this (although I personally tend to use lxml). You should be able to take that data you get, and make a csv file out of is using the csv module without any obvious problems...</p> <p>I think you need to actually tell us what the problem is. "It still doesn't work" is...
2
2009-07-06T10:02:33Z
[ "python", "html", "csv", "screen-scraping", "beautifulsoup" ]
Parsing HTML rows into CSV
1,086,266
<p>First off the html row looks like this: </p> <pre><code>&lt;tr class="evenColor"&gt; blahblah TheTextIneed blahblah and ends with &lt;/tr&gt; </code></pre> <p>I would show the real html but I am sorry to say don't know how to block it. <em>feels shame</em></p> <p>Using BeautifulSoup (Python) or any other recommen...
1
2009-07-06T09:50:25Z
1,086,317
<p>You don't really explain why you are stuck - what's not working exactly?</p> <p>The following line may well be your problem:</p> <pre><code>soup = BeautifulSoup(open(filename["r"])) </code></pre> <p>It looks to me like this should be:</p> <pre><code>soup = BeautifulSoup(open(filename, "r")) </code></pre> <p>The...
4
2009-07-06T10:06:04Z
[ "python", "html", "csv", "screen-scraping", "beautifulsoup" ]
Parsing HTML rows into CSV
1,086,266
<p>First off the html row looks like this: </p> <pre><code>&lt;tr class="evenColor"&gt; blahblah TheTextIneed blahblah and ends with &lt;/tr&gt; </code></pre> <p>I would show the real html but I am sorry to say don't know how to block it. <em>feels shame</em></p> <p>Using BeautifulSoup (Python) or any other recommen...
1
2009-07-06T09:50:25Z
1,086,496
<p>You need to import the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv module</a> by adding <code>import csv</code> to the top of your file.</p> <p>Then you'll need something to create a csv file outside your loop of the rows, like so:</p> <pre><code>writer = csv.writer(open("%s.csv" % filenam...
4
2009-07-06T11:17:50Z
[ "python", "html", "csv", "screen-scraping", "beautifulsoup" ]
Django: information captured from URLs available in template files?
1,086,531
<p>Given:</p> <pre><code>urlpatterns = \ patterns('blog.views', (r'^blog/(?P&lt;year&gt;\d{4})/$', 'year_archive', {'foo': 'bar'}), ) </code></pre> <p>in a urls.py file. (Should it be 'archive_year' instead of 'year_archive' ? - see below for ref.)</p> <p>...
1
2009-07-06T11:33:25Z
1,086,558
<p>No, that's not possible within the URLConf -- the dispatcher has a fixed set of things it does. (It takes the group dictionary from your regex match and passes it as keyword arguments to your view function.) Within your (custom) view function, you should be able to manipulate how those values are passed into the tem...
4
2009-07-06T11:42:37Z
[ "python", "django" ]
How to use QTP to test the application which operates in citrix of Remote Machine?
1,086,758
<p>When i tried recording using QTP, every thing goes well till the application sign in. i.e it gets upto the user Id and password entry, But QTP fails to recognise afterthat. Is there any way to handle this?</p> <p>Application is to be invoked using Citirx, in VPN.</p>
1
2009-07-06T12:40:15Z
1,121,154
<p>QTP performs GUI recognition and interaction through Windows Handle. So it has to be running <strong><em>under</em></strong> Citrix (i.e. installed on the same virtual machine as your Application Under Test). </p> <p>If you have the above, make sure Screen Resolution, Windows Theme, Font size, and other global GUI...
0
2009-07-13T18:13:49Z
[ "c#", "python", "ruby" ]
Can I be warned when I used a generator function by accident
1,087,019
<p>I was working with generator functions and private functions of a class. I am wondering</p> <ol> <li>Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these...
2
2009-07-06T13:38:09Z
1,087,048
<p>A "generator" isn't so much a language feature, as a name for functions that "yield." Yielding is pretty much always legal. There's not really any way for Python to know that you didn't "mean" to yield from some function.</p> <p>This PEP <a href="http://www.python.org/dev/peps/pep-0255/">http://www.python.org/dev...
6
2009-07-06T13:43:41Z
[ "python", "function", "generator", "language-features" ]
Can I be warned when I used a generator function by accident
1,087,019
<p>I was working with generator functions and private functions of a class. I am wondering</p> <ol> <li>Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these...
2
2009-07-06T13:38:09Z
1,087,150
<p>Because the <code>return</code> keyword is applicable in both generator functions and regular functions, there's nothing you could possibly check (as @Christopher mentions). The <code>return</code> keyword in a generator indicates that a StopIteration exception should be raised.</p> <p>If you try to <code>return</c...
1
2009-07-06T14:02:40Z
[ "python", "function", "generator", "language-features" ]
Can I be warned when I used a generator function by accident
1,087,019
<p>I was working with generator functions and private functions of a class. I am wondering</p> <ol> <li>Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these...
2
2009-07-06T13:38:09Z
1,087,249
<p>I'll try to answer the first of your questions.</p> <p>A regular function, when called like this:</p> <pre><code>val = func() </code></pre> <p>executes its inside statements until it ends or a <code>return</code> statement is reached. Then the return value of the function is assigned to <code>val</code>.</p> <p>...
2
2009-07-06T14:21:41Z
[ "python", "function", "generator", "language-features" ]
Can I be warned when I used a generator function by accident
1,087,019
<p>I was working with generator functions and private functions of a class. I am wondering</p> <ol> <li>Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these...
2
2009-07-06T13:38:09Z
1,087,327
<p>Python doesn't know whether you want to create a generator object for later iteration or call a function. But python isn't your only tool for seeing what's going on with your code. If you're using an editor or IDE that allows customized syntax highlighting, you can tell it to give the yield keyword a different col...
2
2009-07-06T14:37:16Z
[ "python", "function", "generator", "language-features" ]
Can I be warned when I used a generator function by accident
1,087,019
<p>I was working with generator functions and private functions of a class. I am wondering</p> <ol> <li>Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these...
2
2009-07-06T13:38:09Z
1,087,399
<p>We do this.</p> <p>Generators have names with "generate" or "gen" in their name. It will have a yield statement in the body. Pretty easy to check visually, since no method is much over 20 lines of code.</p> <p>Other methods don't have "gen" in their name.</p> <p>Also, we do not every use <code>__</code> (double...
0
2009-07-06T14:50:16Z
[ "python", "function", "generator", "language-features" ]
Finding a python process running on Windows with TaskManager
1,087,087
<p>I have several python.exe processes running on my Vista machine and I would like to kill one process thanks to the Windows task manager. What is the best way to find which process to be killed. I've added the 'command line' column on task manager. It can help but not in all cases. is there a better way?</p>
0
2009-07-06T13:49:51Z
1,087,132
<p>Please consider replace Task Manager with the more powerful <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="nofollow">Process Explorer</a> here is a demo:<img src="http://i41.tinypic.com/2i6oozp.jpg" alt="alt text" /></p>
1
2009-07-06T13:59:14Z
[ "python", "windows", "taskmanager" ]
Finding a python process running on Windows with TaskManager
1,087,087
<p>I have several python.exe processes running on my Vista machine and I would like to kill one process thanks to the Windows task manager. What is the best way to find which process to be killed. I've added the 'command line' column on task manager. It can help but not in all cases. is there a better way?</p>
0
2009-07-06T13:49:51Z
38,227,531
<p>When I right clicked python in task manager and clicked open file location (win 10) it opened the plex installation folder so for me it is Plex that uses Python.exe to slow my computer down, shame as I use plex all the time for my Roku. Just have to put up with a slow computer and get another one.</p>
0
2016-07-06T15:13:39Z
[ "python", "windows", "taskmanager" ]
Boolean value of objects in Python
1,087,135
<p>As we know, Python has boolean values for objects: If a class has a <code>__len__</code> method, every instance of it for which <code>__len__()</code> happens to return 0 will be evaluated as a boolean <code>False</code> (for example, the empty list).</p> <p>In fact, every iterable, empty custom object is evaluated...
18
2009-07-06T13:59:55Z
1,087,165
<p>Refer to the Python docs for <a href="https://docs.python.org/2/reference/datamodel.html#object.__nonzero__" rel="nofollow"><code>__nonzero__</code></a>.</p> <pre><code>class foo(object): def __nonzero__( self) : return self.bar % 2 == 0 def a(foo): if foo: print "spam" else: pr...
29
2009-07-06T14:04:57Z
[ "python", "boolean" ]
Boolean value of objects in Python
1,087,135
<p>As we know, Python has boolean values for objects: If a class has a <code>__len__</code> method, every instance of it for which <code>__len__()</code> happens to return 0 will be evaluated as a boolean <code>False</code> (for example, the empty list).</p> <p>In fact, every iterable, empty custom object is evaluated...
18
2009-07-06T13:59:55Z
1,087,166
<p><strong>In Python &lt; 3.0 :</strong></p> <p>You have to use <a href="https://docs.python.org/2/reference/datamodel.html#object.__nonzero__" rel="nofollow"><code>__nonzero__</code></a> to achieve what you want. It's a method that is called automatically by Python when evaluating an object in a boolean context. It m...
31
2009-07-06T14:05:09Z
[ "python", "boolean" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
1,087,413
<p><a href="https://launchpad.net/pyopenssl" rel="nofollow">pyOpenSSL</a> is an interface to the OpenSSL library. It should provide everything you need.</p>
0
2009-07-06T14:52:32Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
1,088,224
<p>You can use Twisted to verify certificates. The main API is <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.ssl.CertificateOptions.html">CertificateOptions</a>, which can be provided as the <code>contextFactory</code> argument to various functions such as <a href="http://twistedmatrix.com/doc...
25
2009-07-06T17:29:48Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
1,441,779
<p><a href="http://chandlerproject.org/Projects/MeTooCrypto">M2Crypto</a> can <a href="http://www.heikkitoivonen.net/blog/2008/10/14/ssl-in-python-26/">do the validation</a>. You can also use <a href="http://svn.osafoundation.org/m2crypto/trunk/M2Crypto/SSL/TwistedProtocolWrapper.py">M2Crypto with Twisted</a> if you li...
8
2009-09-17T23:09:19Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
1,921,551
<p><a href="http://pycurl.sourceforge.net/">PycURL</a> does this beautifully.</p> <p>Below is a short example. It will throw a <code>pycurl.error</code> if something is fishy, where you get a tuple with error code and a human readable message.</p> <pre><code>import pycurl curl = pycurl.Curl() curl.setopt(pycurl.CAIN...
22
2009-12-17T12:48:51Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
3,551,700
<p>Here's an example script which demonstrates certificate validation:</p> <pre><code>import httplib import re import socket import sys import urllib2 import ssl class InvalidCertificateException(httplib.HTTPException, urllib2.URLError): def __init__(self, host, cert, reason): httplib.HTTPException.__init...
14
2010-08-23T21:05:59Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
3,946,778
<p>I have added a distribution to the Python Package Index which makes the <code>match_hostname()</code> function from the Python 3.2 <code>ssl</code> package available on previous versions of Python.</p> <p><a href="http://pypi.python.org/pypi/backports.ssl_match_hostname/">http://pypi.python.org/pypi/backports.ssl_m...
27
2010-10-15T23:06:57Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
6,028,764
<p>Jython DOES carry out certificate verification by default, so using standard library modules, e.g. httplib.HTTPSConnection, etc, with jython will verify certificates and give exceptions for failures, i.e. mismatched identities, expired certs, etc.</p> <p>In fact, you have to do some extra work to get jython to beha...
4
2011-05-17T09:21:43Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
18,767,137
<p>Or simply make your life easier by using the <a href="https://pypi.python.org/pypi/requests" rel="nofollow">requests</a> library:</p> <pre><code>import requests requests.get('https://somesite.com', cert='/path/server.crt', verify=True) </code></pre> <p><a href="http://docs.python-requests.org/en/latest/user/advanc...
11
2013-09-12T14:32:57Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
20,517,707
<p>I was having the same problem but wanted to minimize 3rd party dependencies (because this one-off script was to be executed by many users). My solution was to wrap a <code>curl</code> call and make sure that the exit code was <code>0</code>. Worked like a charm.</p>
0
2013-12-11T11:18:58Z
[ "python", "https", "ssl-certificate", "verification" ]
Validate SSL certificates with Python
1,087,227
<p>I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal corporate Certificate Authority for these sites, so we have the pu...
64
2009-07-06T14:17:34Z
28,325,763
<p>From release version 2.7.9/3.4.3 on, Python <strong>by default</strong> attempts to perform certificate validation.</p> <p>This has been proposed in PEP 467, which is worth a read: <a href="https://www.python.org/dev/peps/pep-0476/">https://www.python.org/dev/peps/pep-0476/</a></p> <p>The changes affect all releva...
8
2015-02-04T15:57:34Z
[ "python", "https", "ssl-certificate", "verification" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,265
<p>The <a href="http://en.wikipedia.org/wiki/Eval#Uses">Wikipedia article on <code>eval</code></a> is pretty informative, and details various uses.</p> <p>Some of the uses it suggests are:</p> <ul> <li>Evaluating mathematical expressions</li> <li><a href="http://en.wikipedia.org/wiki/Bootstrapping%5F%28compilers%29">...
13
2009-07-06T14:24:58Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,278
<p><code>eval()</code> is not normally very useful. One of the few things I have used it for (well, it was <code>exec()</code> actually, but it's pretty similar) was allowing the user to script an application that I wrote in Python. If it were written in something like C++, I would have to embed a Python interpreter in...
1
2009-07-06T14:27:07Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,284
<p>In a program I once wrote, you had an input file where you could specify geometric parameters both as values and as python expressions of the previous values, eg:</p> <pre><code>a=10.0 b=5.0 c=math.log10(a/b) </code></pre> <p>A python parser read this input file and obtained the final data evaluating the values an...
2
2009-07-06T14:28:12Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,295
<p>In the past I have used eval() to add a debugging interface to my application. I created a telnet service which dropped you into the environment of the running application. Inputs were run through eval() so you can interactively run Python commands in the application.</p>
5
2009-07-06T14:29:19Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,300
<p>You may want to use it to allow users to enter their own "scriptlets": <strong>small</strong> expressions (or even small functions), that can be used to customize the behavior of a <strong>complex</strong> system.<br /> In that context, and if you do not have to care too much for the security implications (e.g. you ...
11
2009-07-06T14:31:22Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,311
<p>Eval is a way to interact with the Python interpreter from within a program. You can pass literals to eval and it evaluates them as python expressions.</p> <p>For example - </p> <pre><code>print eval("__import__('os').getcwd()") </code></pre> <p>would return the current working directory.</p> <p>cheers</p>
1
2009-07-06T14:33:46Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,479
<p>I use it as a quick JSON parser ...</p> <pre><code>r=''' { "glossary": { "title": "example glossary" } } ''' print eval(r)['glossary']['title'] </code></pre>
-1
2009-07-06T15:03:08Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,625
<p><code>eval</code> and <code>exec</code> are handy quick-and-dirty way to get some source code dynamically, maybe munge it a bit, and then execute it -- but they're hardly ever the best way, especially in production code as opposed to "quick-and-dirty" prototypes &amp;c.</p> <p>For example, if I had to deal with suc...
29
2009-07-06T15:30:21Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
1,087,675
<p>I use <code>exec</code> to create a system of plugins in Python.</p> <pre> try: exec ("from " + plugin_name + " import Plugin") myplugin = Plugin(module_options, config=config) except ImportError, message: fatal ("No such module " + plugin_name + \ " (or no Plugin cons...
-2
2009-07-06T15:39:25Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
21,995,852
<p>I used it to input variable values to the main program:</p> <p>test.py var1=2 var2=True</p> <p>...</p> <pre><code>var1=0 var2=False for arg in sys.argv[1:]: exec(arg) </code></pre> <p>A crude way to allow keyword args in the main program. If there's a better way let me know!</p>
0
2014-02-24T18:22:29Z
[ "python", "dynamic", "eval" ]
Use of eval in Python?
1,087,255
<p>There is an <code>eval()</code> function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example?</p>
15
2009-07-06T14:23:07Z
23,626,496
<p>eval() is for single sentence, while exec() is for multiple ones.</p> <p>usually we use them to add or visit some scripts just like bash shell.</p> <p>because of they can run some byte scripts in the memory, if you have some important data or script you can decode and unzip your 'secret' then do everything you wan...
-1
2014-05-13T08:42:40Z
[ "python", "dynamic", "eval" ]
Reportlab page x of y NumberedCanvas and Images
1,087,495
<p>I had been using the reportlab NumberedCanvas given at <a href="http://code.activestate.com/recipes/546511/" rel="nofollow">http://code.activestate.com/recipes/546511/</a> . However, when i try to build a PDF that contains Image flowables, the images do not show, although enough vertical space is left for the image ...
4
2009-07-06T15:05:23Z
1,088,029
<p>See <a href="http://code.activestate.com/recipes/576832/">my new, improved recipe</a> for this, which includes a simple test with images. Here's an excerpt from the recipe (which omits the test code):</p> <pre><code>from reportlab.pdfgen import canvas from reportlab.lib.units import mm class NumberedCanvas(canvas....
13
2009-07-06T16:51:06Z
[ "python", "reportlab" ]
Starting and Controlling an External Process via STDIN/STDOUT with Python
1,087,799
<p>I need to launch an external process that is to be controlled via messages sent back and forth via stdin and stdout. Using subprocess.Popen I am able to start the process but am unable to control the execution via stdin as I need to. </p> <p>The flow of what I'm trying to complete is to:</p> <ol> <li>Start the e...
4
2009-07-06T16:03:57Z
1,087,883
<p>process.communicate(input='\n') is wrong. If you will notice from the Python docs, it writes your string to the stdin of the child, then reads all output from the child until the child exits. From doc.python.org:</p> <blockquote> <p>Popen.communicate(input=None) Interact with process: Send data to stdin. Read ...
8
2009-07-06T16:18:06Z
[ "python", "subprocess" ]
Starting and Controlling an External Process via STDIN/STDOUT with Python
1,087,799
<p>I need to launch an external process that is to be controlled via messages sent back and forth via stdin and stdout. Using subprocess.Popen I am able to start the process but am unable to control the execution via stdin as I need to. </p> <p>The flow of what I'm trying to complete is to:</p> <ol> <li>Start the e...
4
2009-07-06T16:03:57Z
1,103,295
<p>You could use Twisted, by using <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.interfaces.IReactorProcess.spawnProcess.html" rel="nofollow">reactor.spawnProcess</a> and <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.protocols.basic.LineReceiver.html" rel="nofollow">LineReceiver...
0
2009-07-09T11:29:37Z
[ "python", "subprocess" ]
testing python applications that use mysql
1,088,077
<p>I want to write some unittests for an application that uses MySQL. However, I do not want to connect to a real mysql database, but rather to a temporary one that doesn't require any SQL server at all.</p> <p>Any library (I could not find anything on google)? Any design pattern? Note that DIP doesn't work since I wi...
5
2009-07-06T17:00:00Z
1,088,090
<p>There isn't a good way to do that. You want to run your queries against a real MySQL server, otherwise you don't know if they will work or not.</p> <p>However, that doesn't mean you have to run them against a production server. We have scripts that create a Unit Test database, and then tear it down once the unit t...
8
2009-07-06T17:04:00Z
[ "python", "mysql", "unit-testing" ]
testing python applications that use mysql
1,088,077
<p>I want to write some unittests for an application that uses MySQL. However, I do not want to connect to a real mysql database, but rather to a temporary one that doesn't require any SQL server at all.</p> <p>Any library (I could not find anything on google)? Any design pattern? Note that DIP doesn't work since I wi...
5
2009-07-06T17:00:00Z
1,088,093
<p>I've used <a href="http://python-mock.sourceforge.net/" rel="nofollow">python-mock</a> and <a href="http://code.google.com/p/pymox/" rel="nofollow">mox</a> for such purposes (<em>extremely</em> lightweight tests that absolutely cannot require ANY SQL server), but for more extensive/in-depth testing, starting and pop...
4
2009-07-06T17:04:44Z
[ "python", "mysql", "unit-testing" ]
Python: accessing DLL function using ctypes -- access by function *name* fails
1,088,085
<p><code>myPythonClient</code> (below) wants to invoke a <code>ringBell</code> function (loaded from a DLL using <code>ctypes</code>). However, attempting to access <code>ringBell</code> via its <em>name</em> results in an <code>AttributeError</code>. Why?</p> <p><code>RingBell.h</code> contains</p> <pre><code>names...
5
2009-07-06T17:02:09Z
1,088,111
<p>Perhaps because the C++ name is mangled by the compiler and not exported from the DLL as <code>RingBell</code>. Have you checked that it appears in the exported names exactly like that?</p>
6
2009-07-06T17:08:32Z
[ "python", "dll", "ctypes", "attributeerror" ]
Python: accessing DLL function using ctypes -- access by function *name* fails
1,088,085
<p><code>myPythonClient</code> (below) wants to invoke a <code>ringBell</code> function (loaded from a DLL using <code>ctypes</code>). However, attempting to access <code>ringBell</code> via its <em>name</em> results in an <code>AttributeError</code>. Why?</p> <p><code>RingBell.h</code> contains</p> <pre><code>names...
5
2009-07-06T17:02:09Z
1,088,142
<p>Your C++ compiler is mangling the names of all externally visible objects to reflect (as well as their underlying names) their namespaces, classes, and signatures (that's how overloading becomes possible).</p> <p>In order to avoid this mangling, you need an <code>extern "C"</code> on externally visible names that ...
9
2009-07-06T17:13:35Z
[ "python", "dll", "ctypes", "attributeerror" ]
Python: accessing DLL function using ctypes -- access by function *name* fails
1,088,085
<p><code>myPythonClient</code> (below) wants to invoke a <code>ringBell</code> function (loaded from a DLL using <code>ctypes</code>). However, attempting to access <code>ringBell</code> via its <em>name</em> results in an <code>AttributeError</code>. Why?</p> <p><code>RingBell.h</code> contains</p> <pre><code>names...
5
2009-07-06T17:02:09Z
8,473,993
<p>All is working now :) To summarize your posts:</p> <p>Write DLL in C++:</p> <pre><code>// Header extern "C" { // Name in DLL will be "MyAdd" - but you won't be able to find parameters etc... __declspec(dllexport) int MyAdd(int a, int b); } // Name will be with lot of prefixes but some other info is provide...
5
2011-12-12T12:02:01Z
[ "python", "dll", "ctypes", "attributeerror" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
1,088,359
<p><a href="http://docs.python.org/library/ftplib.html?highlight=ftplib#ftplib.FTP.dir"><code>FTP.dir</code></a> returns a directory listing, that you can parse with a callback function to find out whether it's a directory. For example, like this:</p> <pre><code>def parse(line): if line[0] == 'd': print(li...
5
2009-07-06T17:55:52Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
1,088,393
<pre><code>def is_file(filename): return ftp.size(filename) is not None </code></pre> <p>This works because ftp.size returns None if it is a directory.</p>
1
2009-07-06T18:01:04Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
1,088,645
<pre><code>def is_file(filename): current = ftp.pwd() try: ftp.cwd(filename) except: ftp.cwd(current) return True ftp.cwd(current) return False </code></pre> <p>Here is another solution. Half way writing it out I realized it has a problem. If you don't have permission to cha...
0
2009-07-06T18:49:41Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
1,985,617
<p>FTP is quite a rudimentary protocol and there's no built-in protocol query allowing you to get the type (file, dir) of each node, so a heuristic like the one you found is the only solution.</p> <p>If getting the size of each node doesn't work, perhaps you should consider calling <a href="http://docs.python.org/libr...
6
2009-12-31T14:28:08Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
8,474,577
<p>You can use MLST command:</p> <pre><code>import ftplib f = ftplib.FTP() f.connect("localhost") f.login() print f.sendcmd('MLST /') </code></pre> <p>Against <a href="http://code.google.com/p/pyftpdlib/" rel="nofollow">pyftpdlib server</a> the code above prints:</p> <pre><code>250-Listing "/": modify=2011121212483...
1
2011-12-12T12:51:09Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
10,658,892
<p>I have used this when dealing with ftplib:</p> <pre><code>import ftplib from ftplib import FTP ftp=FTP("ftp address") ftp.login("user","password") path = "/is/this/a/file/or/a/folder/" try: ftp.cwd(path) print "it's a folder!" except ftplib.error_perm: print "it's not a folder!" </code></pre>
1
2012-05-18T19:52:42Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
16,729,691
<p>This is what I use for finding the directories in a given directory. I return the directory names as a set because I use sets later on in the program, but you could leave off the set creation at the end and return the directory names as a list, tuple, etc.</p> <pre class="lang-py prettyprint-override"><code>def get...
1
2013-05-24T07:24:38Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
27,321,502
<p>I have found a solution, but it may not be the best and I think it can be helpful for you.</p> <pre><code>&gt; def isfile(remote_name): &gt; try: &gt; ftp.sendcmd('MDTM ' + remote_name) &gt; except: &gt; return False &gt; else: &gt; return True </code></pre> <p>This function wil...
0
2014-12-05T17:29:33Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
28,141,179
<p>All files have an extension, so by using split('.') it can be broken into a list of size 2. While for directories the size of list will be one after using split('.'). So by checking size of list we can identify if its a file or a directory.</p> <pre><code>os.chdir(r"path") ftp = ftplib.FTP('ftp.some.server') ftp.lo...
-2
2015-01-25T20:37:04Z
[ "python", "ftp", "ftplib" ]
ftplib checking if a file is a folder?
1,088,336
<p>How can i check if a file on a remote ftp is a folder or not using ftplib?</p> <p>Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder?</p> <p>Is there a better way? I cannot parse the output of list, since there is about a doz...
11
2009-07-06T17:49:49Z
39,980,353
<p>There are not "isdir" and "isfile" definitions in ftplib. If you don't have to use ftplib, i recommend you to use <a href="http://ftputil.sschwarzer.net/trac/wiki/Documentation" rel="nofollow">ftputil</a>. </p> <p>First of all you have to install ftputil package. To achive this, use this command: <code>python -m pi...
0
2016-10-11T15:01:01Z
[ "python", "ftp", "ftplib" ]
Sorting a Python list by key... while checking for string OR float?
1,088,392
<p>Ok, I've got a list like this (just a sample of data):</p> <pre><code>data = {"NAME": "James", "RANK": "3.0", "NUM": "27.5" ... } </code></pre> <p>Now, if I run something like this:</p> <pre><code>sortby = "NAME" //this gets passed to the function, hence why I am using a variable sortby instead data.sort(key=item...
1
2009-07-06T18:00:59Z
1,088,433
<p>Slightly more verbose than just passing a field name, but this is an option:</p> <pre><code>sort_by_name = lambda x: x['name'] sort_by_rank = lambda x: float(x['RANK']) # etc... data.sort(key=sort_by_rank) </code></pre> <p>If the data is much more dense than what you've posted, you might want a separate dictionar...
0
2009-07-06T18:09:23Z
[ "python", "list", "sorting" ]
Sorting a Python list by key... while checking for string OR float?
1,088,392
<p>Ok, I've got a list like this (just a sample of data):</p> <pre><code>data = {"NAME": "James", "RANK": "3.0", "NUM": "27.5" ... } </code></pre> <p>Now, if I run something like this:</p> <pre><code>sortby = "NAME" //this gets passed to the function, hence why I am using a variable sortby instead data.sort(key=item...
1
2009-07-06T18:00:59Z
1,088,444
<p>if you cant save your data properly ( floats as <em>floats</em> ), something like this</p> <pre><code>sorters = { "NAME" : itemgetter("NAME"), "RANK" : lambda x: float(x["RANK"]), "NUM" : lambda x: float(x["NUM"]) } data.sort(key=sorters[sortby]) </code></pre>
4
2009-07-06T18:11:25Z
[ "python", "list", "sorting" ]
Sorting a Python list by key... while checking for string OR float?
1,088,392
<p>Ok, I've got a list like this (just a sample of data):</p> <pre><code>data = {"NAME": "James", "RANK": "3.0", "NUM": "27.5" ... } </code></pre> <p>Now, if I run something like this:</p> <pre><code>sortby = "NAME" //this gets passed to the function, hence why I am using a variable sortby instead data.sort(key=item...
1
2009-07-06T18:00:59Z
1,088,538
<p>If you want a general function which you can pass as a parameter to <code>sort(key=XXX)</code>, then here's a candidate complete with test:</p> <pre><code>DATA = [ { 'name' : 'A', 'value' : '10.0' }, { 'name' : 'B', 'value' : '2.0' }, ] def get_attr(name): def inner_func(o): try: rv...
7
2009-07-06T18:29:42Z
[ "python", "list", "sorting" ]
Adding attributes into Django Model's Meta class
1,088,431
<p>I'm writing a mixin which will allow my Models to be easily translated into a deep dict of values (kind of like .values(), but traversing relationships). The cleanest place to do the definitions of these seems to be in the models themselves, a la:</p> <pre><code>class Person(models.Model, DeepValues): name = mo...
24
2009-07-06T18:08:21Z
1,088,649
<p>I don't know about elegant, but one pragmatic way is:</p> <pre><code>import django.db.models.options as options options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('schema',) </code></pre> <p>Obviously, this would break if Django ever added a 'schema' attribute of its own. But hey, it's a thought...you could always ...
36
2009-07-06T18:50:36Z
[ "python", "django", "django-models", "metadata" ]
HTML inside node using ElementTree
1,088,476
<p>I am using ElementTree to parse a XML file. In some fields, there will be HTML data. For example, consider a declaration as follows:</p> <pre><code>&lt;Course&gt; &lt;Description&gt;Line 1&lt;br /&gt;Line 2&lt;/Description&gt; &lt;/Course&gt; </code></pre> <p>Now, supposing _course is an Element variable which...
3
2009-07-06T18:17:47Z
1,088,498
<p>Do you have any control over the creation of the xml file? The contents of xml tags which contain xml tags (or similar), or markup chars ('<code>&lt;</code>', etc) should be encoded to avoid this problem. You can do this with either:</p> <ul> <li>a <a href="http://en.wikipedia.org/wiki/Cdata" rel="nofollow">CDATA</...
3
2009-07-06T18:22:37Z
[ "python", "html", "xml", "elementtree" ]
HTML inside node using ElementTree
1,088,476
<p>I am using ElementTree to parse a XML file. In some fields, there will be HTML data. For example, consider a declaration as follows:</p> <pre><code>&lt;Course&gt; &lt;Description&gt;Line 1&lt;br /&gt;Line 2&lt;/Description&gt; &lt;/Course&gt; </code></pre> <p>Now, supposing _course is an Element variable which...
3
2009-07-06T18:17:47Z
1,088,517
<p>Characters like "&lt;" and "&amp;" are illegal in XML elements.</p> <p>"&lt;" will generate an error because the parser interprets it as the start of a new element.</p> <p>"&amp;" will generate an error because the parser interprets it as the start of an character entity.</p> <p>Some text, like JavaScript code, c...
1
2009-07-06T18:25:28Z
[ "python", "html", "xml", "elementtree" ]
HTML inside node using ElementTree
1,088,476
<p>I am using ElementTree to parse a XML file. In some fields, there will be HTML data. For example, consider a declaration as follows:</p> <pre><code>&lt;Course&gt; &lt;Description&gt;Line 1&lt;br /&gt;Line 2&lt;/Description&gt; &lt;/Course&gt; </code></pre> <p>Now, supposing _course is an Element variable which...
3
2009-07-06T18:17:47Z
6,653,844
<p>You are trying to read the tail attribute from the wrong element. Try</p> <pre><code>desc = _course.find("br").tail; </code></pre> <p>The tail attribute is used to store trailing text nodes when reading mixed-content XML files; text that follows directly after an element are stored in the tail attribute for that e...
3
2011-07-11T17:13:53Z
[ "python", "html", "xml", "elementtree" ]
HTML inside node using ElementTree
1,088,476
<p>I am using ElementTree to parse a XML file. In some fields, there will be HTML data. For example, consider a declaration as follows:</p> <pre><code>&lt;Course&gt; &lt;Description&gt;Line 1&lt;br /&gt;Line 2&lt;/Description&gt; &lt;/Course&gt; </code></pre> <p>Now, supposing _course is an Element variable which...
3
2009-07-06T18:17:47Z
6,711,116
<p>Inspired by <a href="http://stackoverflow.com/questions/1088476/html-inside-node-using-elementtree/6653844#6653844">user839338's answer</a>, I wen't and looked for a reasonable solution, which looks a bit like this.</p> <pre><code>&gt;&gt;&gt; from xml.etree import ElementTree as etree &gt;&gt;&gt; corpus = '''&lt;...
1
2011-07-15T17:46:02Z
[ "python", "html", "xml", "elementtree" ]
Python Libraries for FTP Upload/Download?
1,088,518
<p>Okay so a bit of forward:</p> <p>We have a service/daemon written in python that monitors remote ftp sites. These sites are not under our command, some of them we do NOT have del/rename/write access, some also are running extremely old ftp software. Such that certain commands do not work. There is no standardizatio...
1
2009-07-06T18:26:01Z
1,088,557
<p>You may have better luck with one of the cURL bindings such as <a href="http://pycurl.sourceforge.net/" rel="nofollow">pycURL</a>.</p>
1
2009-07-06T18:33:47Z
[ "python", "ftp", "ftplib" ]
Python Libraries for FTP Upload/Download?
1,088,518
<p>Okay so a bit of forward:</p> <p>We have a service/daemon written in python that monitors remote ftp sites. These sites are not under our command, some of them we do NOT have del/rename/write access, some also are running extremely old ftp software. Such that certain commands do not work. There is no standardizatio...
1
2009-07-06T18:26:01Z
1,088,625
<p>You don't mention which alternatives you've looked at already. Is ftputil one of them?</p> <p><a href="http://ftputil.sschwarzer.net/trac/wiki/Documentation" rel="nofollow">http://ftputil.sschwarzer.net/trac/wiki/Documentation</a></p> <p>If you're trying to code around edge cases from various server implementation...
1
2009-07-06T18:47:08Z
[ "python", "ftp", "ftplib" ]
App Engine db.model reference question
1,088,678
<p>How can I get at the Labels data from within my Task model?</p> <pre><code>class Task(db.Model): title = db.StringProperty() class Label(db.Model): name = db.StringProperty() class Tasklabel(db.Model): task = db.ReferenceProperty(Task) label = db.ReferenceProperty(Label) </code></pre> <p>creating the ass...
0
2009-07-06T18:57:05Z
1,088,766
<p>Don't you want a <a href="http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#Lists" rel="nofollow">ListProperty</a> on Task like this to do a many-to-many?</p> <pre><code>class Label(db.Model) name = db.StringProperty() @property def members(self): return Task.gql("WHERE l...
1
2009-07-06T19:17:38Z
[ "python", "google-app-engine" ]
App Engine db.model reference question
1,088,678
<p>How can I get at the Labels data from within my Task model?</p> <pre><code>class Task(db.Model): title = db.StringProperty() class Label(db.Model): name = db.StringProperty() class Tasklabel(db.Model): task = db.ReferenceProperty(Task) label = db.ReferenceProperty(Label) </code></pre> <p>creating the ass...
0
2009-07-06T18:57:05Z
1,089,470
<p>This worked for me with your current datamodel:</p> <pre><code>taskObject = db.Query(Task).get() for item in taskObject.tasklabel_set: item.label.name </code></pre> <p>Or you could remove the Label class and just do a one-to-many relationship between Task and TaskLabel:</p> <pre><code>class Task(db.Model)...
2
2009-07-06T22:20:21Z
[ "python", "google-app-engine" ]
Django Reporting Options
1,088,738
<p>I want to create a new "Business" application using the Django framework. Any suggestions as to what I can use as a reporting framework? The application will need to generate reports on various business entities including summaries, totals, grouping, etc. Basically, is there a Crystal reports-like equivalent for D...
9
2009-07-06T19:11:27Z
1,088,917
<p>These are just HTML templates with ordinary view functions.</p> <p>This doesn't require much: Parameters come in from a form; write the query in the view function, passing the queryset to the template. The template presents the report.</p> <p>Why would you need something more than this? </p> <p>You can use <a h...
1
2009-07-06T19:56:09Z
[ "python", "django", "reporting" ]
Django Reporting Options
1,088,738
<p>I want to create a new "Business" application using the Django framework. Any suggestions as to what I can use as a reporting framework? The application will need to generate reports on various business entities including summaries, totals, grouping, etc. Basically, is there a Crystal reports-like equivalent for D...
9
2009-07-06T19:11:27Z
1,088,974
<p>There is a grid on djangopackages.com which may be of use evaluating options:</p> <p><a href="https://www.djangopackages.com/grids/g/reporting/" rel="nofollow">https://www.djangopackages.com/grids/g/reporting/</a></p>
5
2009-07-06T20:07:55Z
[ "python", "django", "reporting" ]
Django Reporting Options
1,088,738
<p>I want to create a new "Business" application using the Django framework. Any suggestions as to what I can use as a reporting framework? The application will need to generate reports on various business entities including summaries, totals, grouping, etc. Basically, is there a Crystal reports-like equivalent for D...
9
2009-07-06T19:11:27Z
1,092,513
<p><strong>Edit</strong> It really looks like both packages are gone, but now we have a nice data structure, borrowed from R -- <a href="http://pandas.pydata.org/pandas-docs/stable/dsintro.html#dataframe" rel="nofollow">DataFrame</a> in pandas package <a href="http://gregreda.com/2013/10/26/working-with-pandas-datafram...
0
2009-07-07T13:59:14Z
[ "python", "django", "reporting" ]
Django Reporting Options
1,088,738
<p>I want to create a new "Business" application using the Django framework. Any suggestions as to what I can use as a reporting framework? The application will need to generate reports on various business entities including summaries, totals, grouping, etc. Basically, is there a Crystal reports-like equivalent for D...
9
2009-07-06T19:11:27Z
19,415,730
<p>I made <a href="https://github.com/burke-software/django-report-builder" rel="nofollow">django-report-builder</a>. It lets you build ORM queries with a gui and generate spreadsheet reports. It can't do templates, that would be a great feature to add though.</p>
4
2013-10-16T23:28:17Z
[ "python", "django", "reporting" ]
How to print output using python?
1,088,764
<p>When this .exe file runs it prints a screen full of information and I want to print a particular line out to the screen, here on line "6":</p> <pre><code> cmd = ' -a ' + str(a) + ' -b ' + str(b) + str(Output) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstring = process.communicate...
3
2009-07-06T19:17:08Z
1,088,783
<p>Like you said, a variable has to be declared before you can use it. Therefore when you call <code>str(Output)</code> ABOVE <code>Output = outputlist[5]</code>, Output doesn't exist yet. You need the actually call first:</p> <pre><code>cmd = ' -a ' + str(a) + ' -b ' + str(b) </code></pre> <p>then you can print the...
0
2009-07-06T19:21:55Z
[ "python" ]
How to print output using python?
1,088,764
<p>When this .exe file runs it prints a screen full of information and I want to print a particular line out to the screen, here on line "6":</p> <pre><code> cmd = ' -a ' + str(a) + ' -b ' + str(b) + str(Output) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstring = process.communicate...
3
2009-07-06T19:17:08Z
1,088,790
<p>You're trying to append the result of a call into the call itself. You have to run the command once without the <code>+ str(Output)</code> part to get the output in the first place.</p> <p>Think about it this way. Let's say I was adding some numbers together.</p> <pre><code> z = 5 + b b = z + 2 </code></pre> <p>...
5
2009-07-06T19:23:55Z
[ "python" ]
How to print output using python?
1,088,764
<p>When this .exe file runs it prints a screen full of information and I want to print a particular line out to the screen, here on line "6":</p> <pre><code> cmd = ' -a ' + str(a) + ' -b ' + str(b) + str(Output) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstring = process.communicate...
3
2009-07-06T19:17:08Z
1,088,818
<p>It's not supposed to be a "dance" to move things around. It's a matter of what's on the left side of the "=". If it's on the left side, it's getting created; if it's on the right side it's being used. </p> <p>As it is, your example can't work even a little bit because line one wants part of output, which isn't c...
1
2009-07-06T19:30:42Z
[ "python" ]
How to print output using python?
1,088,764
<p>When this .exe file runs it prints a screen full of information and I want to print a particular line out to the screen, here on line "6":</p> <pre><code> cmd = ' -a ' + str(a) + ' -b ' + str(b) + str(Output) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstring = process.communicate...
3
2009-07-06T19:17:08Z
1,088,828
<p>Just change your first line to:</p> <p>cmd = ' -a ' + str(a) + ' -b ' + str(b)</p> <p>and the print statement at the end to:</p> <p>print cmd + str(Output)</p> <p>This is without knowing exactly what it is you want to print... It -seems- as if your problem is trying to use Output before you actually define what ...
1
2009-07-06T19:33:26Z
[ "python" ]