title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 20,158,605 | <blockquote>
<h1>What does the <code>if __name__ == "__main__":</code> do?</h1>
</blockquote>
<p>The global variable, <code>__name__</code>, in the module that is the entry point to your program, is <code>'__main__'</code>. </p>
<p>So, code in this <code>if</code> block will only run if that module is the entry poi... | 241 | 2013-11-23T04:38:25Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 20,517,795 | <p>When you run Python interactively the local <code>__name__</code> variable is assigned a value of <code>__main__</code>. Likewise, when you execute a Python module from the command line, rather than importing it into another module, its <code>__name__</code> attribute is assigned a value of <code>__main__</code>, ra... | 15 | 2013-12-11T11:23:53Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 26,369,628 | <blockquote>
<h1>What does <code>if __name__ == â__main__â:</code> do?</h1>
</blockquote>
<p><code>__name__</code> is a global variable (in Python, global actually means on the <a href="https://docs.python.org/tutorial/modules.html#modules" rel="nofollow">module level</a>) that exists in all namespaces. It is ty... | 28 | 2014-10-14T20:22:55Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 28,051,929 | <p>Let's look at the answer in a more abstract way:</p>
<p>Suppose we have this code in x.py:</p>
<pre><code>...
<Block A>
if __name__ == '__main__':
<Block B>
...
</code></pre>
<p>Blocks A and B are run when we are running "x.py".</p>
<p>But just block A (and not B) is run when we are running anoth... | 15 | 2015-01-20T17:48:56Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 33,916,552 | <p>There are a number of variables that the system (Python interpreter) provides for source files (modules). You can get their values anytime you want, so, let us focus on the <strong>__name__</strong> variable/attribute:</p>
<p>When Python loads a source code file, it executes all of the code found in it. (Note that... | 7 | 2015-11-25T12:26:57Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 36,820,845 | <p><strong><em>if __name__ == "__main__":</em></strong> is basically Top-level script environment, it specifies the interpreter that ('I have the highest priority to be executed first').</p>
<p><strong><em>'__main__</em></strong>' is the name of the scope in which top-level code executes. A moduleâs <strong>name</st... | 4 | 2016-04-24T08:23:01Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 37,965,772 | <pre><code>print __name__
</code></pre>
<p>output for the above is <strong>main</strong> </p>
<pre><code>if __name == "__main__":
print direct method
</code></pre>
<p>the above statement is gets true and print direct method suppose if they imported this class in other class it doesnt print direct method .because w... | 0 | 2016-06-22T10:47:06Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 39,761,460 | <p>Lots of different takes here on the mechanics of the code in question, the "How", but for me none of it made sense until I understood the "Why". This should be especially helpful for new programmers.</p>
<p>Take this example:</p>
<p>File "ab.py":</p>
<pre><code>def a():
print('A function in ab file');
a()
</c... | 3 | 2016-09-29T04:33:07Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 40,057,173 | <p>Put Simply <code>__name__</code> is a variable defined for each script, that defines whether the script is being run as the main module or it is being run as an imported module. </p>
<p>So if we have two scripts;</p>
<pre><code>#script1.py
print "Script 1's name:".format(__name__)
</code></pre>
<p>and ;</p>
<pre... | 0 | 2016-10-15T09:07:42Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
How do you query the set of Users in Google App Domain within your Google App Engine project? | 419,197 | <p>If you have a Google App Engine project you can authenticate based on either a) anyone with a google account or b) a particular google app domain. Since you can connect these two entities I would assume there is some way to query the list of users that can be authenticated. The use case is outputting a roster of all... | 0 | 2009-01-07T04:33:53Z | 419,852 | <p>There's nothing built in to App Engine to do this. If you have Apps Premium edition, however, you can use the <a href="http://code.google.com/apis/apps/reporting/google_apps_reporting_api.html" rel="nofollow">reporting API</a>.</p>
| 1 | 2009-01-07T10:38:41Z | [
"python",
"google-app-engine",
"google-apps",
"gql",
"gqlquery"
] |
How do you query the set of Users in Google App Domain within your Google App Engine project? | 419,197 | <p>If you have a Google App Engine project you can authenticate based on either a) anyone with a google account or b) a particular google app domain. Since you can connect these two entities I would assume there is some way to query the list of users that can be authenticated. The use case is outputting a roster of all... | 0 | 2009-01-07T04:33:53Z | 422,468 | <p>Querying all users that could possibly authenticate in the case of 'a' (all gmail users) would be millions and millions users, so I'm sure you don't expect to do that. </p>
<p>I'm sure you actually mean query the ones who have logged into your application previously, in which case you just create a table to store t... | 2 | 2009-01-07T22:31:57Z | [
"python",
"google-app-engine",
"google-apps",
"gql",
"gqlquery"
] |
How do you query the set of Users in Google App Domain within your Google App Engine project? | 419,197 | <p>If you have a Google App Engine project you can authenticate based on either a) anyone with a google account or b) a particular google app domain. Since you can connect these two entities I would assume there is some way to query the list of users that can be authenticated. The use case is outputting a roster of all... | 0 | 2009-01-07T04:33:53Z | 426,287 | <p>Yeah, there's no way to get information about people who haven't logged into your application.</p>
| 0 | 2009-01-08T22:27:33Z | [
"python",
"google-app-engine",
"google-apps",
"gql",
"gqlquery"
] |
How do you query the set of Users in Google App Domain within your Google App Engine project? | 419,197 | <p>If you have a Google App Engine project you can authenticate based on either a) anyone with a google account or b) a particular google app domain. Since you can connect these two entities I would assume there is some way to query the list of users that can be authenticated. The use case is outputting a roster of all... | 0 | 2009-01-07T04:33:53Z | 455,902 | <p>You would have to use the Premium (or Education) Google apps version, and you can use the api to list all users in the apps domain: </p>
<p><code>GET https://apps-apis.google.com/a/feeds/domain/user/2.0</code></p>
<p>see docs here:</p>
<p><a href="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_refer... | 1 | 2009-01-18T21:14:07Z | [
"python",
"google-app-engine",
"google-apps",
"gql",
"gqlquery"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 419,253 | <p>I've used <a href="http://ruya.sourceforge.net/" rel="nofollow">Ruya</a> and found it pretty good.</p>
| 3 | 2009-01-07T05:07:59Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 419,255 | <p>Check the <a href="http://bulba.sdsu.edu/docwiki/HarvestMan">HarvestMan</a>, a multi-threaded web-crawler written in Python, also give a look to the <a href="http://pypi.python.org/pypi/spider.py/0.5">spider.py</a> module.</p>
<p>And <a href="http://www.example-code.com/python/pythonspider.asp">here</a> you can fin... | 6 | 2009-01-07T05:11:40Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 419,259 | <ul>
<li><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">Mechanize</a> is my favorite; great high-level browsing capabilities (super-simple form filling and submission).</li>
<li><a href="http://twill.idyll.org/" rel="nofollow">Twill</a> is a simple scripting language built on top of Mechanize</li>... | 56 | 2009-01-07T05:13:20Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 421,645 | <p>Use <a href="http://scrapy.org/" rel="nofollow">Scrapy</a>.</p>
<p>It is a twisted-based web crawler framework. Still under heavy development but it works already. Has many goodies:</p>
<ul>
<li>Built-in support for parsing HTML, XML, CSV, and Javascript</li>
<li>A media pipeline for scraping items with images (or... | 44 | 2009-01-07T19:11:00Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 1,906,601 | <p>Another <a href="http://www.grenadepod.com/2009/12/13/python-web-crawler/" rel="nofollow">simple spider</a>
Uses BeautifulSoup and urllib2. Nothing too sophisticated, just reads all a href's builds a list and goes though it.</p>
| 2 | 2009-12-15T10:47:30Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 3,427,062 | <p><a href="http://bauerdata.bauerhost.dk/python-program-eksempler/pyspider" rel="nofollow">pyspider.py</a></p>
| 0 | 2010-08-06T19:25:55Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 4,153,223 | <p>I hacked the above script to include a login page as I needed it to access a drupal site. Not pretty but may help someone out there.</p>
<pre><code>#!/usr/bin/python
import httplib2
import urllib
import urllib2
from cookielib import CookieJar
import sys
import re
from HTMLParser import HTMLParser
class miniHTMLPa... | 3 | 2010-11-11T10:04:04Z | [
"python",
"web-crawler"
] |
Anyone know of a good Python based web crawler that I could use? | 419,235 | <p>I'm half-tempted to write my own, but I don't really have enough time right now. I've seen the Wikipedia list of <a href="http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers" rel="nofollow">open source crawlers</a> but I'd prefer something written in Python. I realize that I could probably just use one o... | 67 | 2009-01-07T04:53:21Z | 8,310,728 | <p>Trust me nothing is better than curl.. . the following code can crawl 10,000 urls in parallel in less than 300 secs on Amazon EC2</p>
<p><strong>CAUTION:</strong> <em>Don't hit the same domain at such a high speed.. .</em></p>
<pre><code>#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
# vi:ts=4:et
# $Id: retri... | 3 | 2011-11-29T12:32:03Z | [
"python",
"web-crawler"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,267 | <p>Since you write in C, you may want to check out <a href="http://curl.haxx.se/" rel="nofollow" title="cURL">cURL</a>; in particular, take a look at libcurl. It's great.</p>
| 3 | 2009-01-07T05:17:13Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,268 | <p><a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Quick%20Start" rel="nofollow">Beautiful Soup</a> is a Python library designed for parsing web pages. Between it and <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a> (<a href="http://docs.python.org/py3k/library/u... | 11 | 2009-01-07T05:17:21Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,269 | <p>What you're asking about is called "web scraping." I'm sure if you google around you'll find some stuff, but the core notion is that you want to open a connection to the website, slurp in the HTML, parse it and identify the chunks you want.</p>
<p>The <a href="http://wiki.python.org/moin/WebProgramming">Python Wik... | 5 | 2009-01-07T05:18:24Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,271 | <p>That site doesnt offer an API for you to be able to get the appropriate data that you need. In that case you'll need to parse the actual HTML page returned by, for example, a CURL request .</p>
| 1 | 2009-01-07T05:19:33Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,273 | <p>As long as the layout of the web page your trying to 'scrape' doesnt regularly change, you should be able to parse the html with any modern day programming language.</p>
| 0 | 2009-01-07T05:20:06Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,285 | <p>This is called <strong>Web scraping</strong>, and it even has its own <a href="http://en.wikipedia.org/wiki/Web_scraping" rel="nofollow">Wikipedia article</a> where you can find more information.</p>
<p>Also, you might find more details in this <a href="http://stackoverflow.com/questions/419235/anyone-know-of-a-goo... | 1 | 2009-01-07T05:27:11Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,298 | <p>You can use Perl to help you complete your task.</p>
<pre><code>use strict;
use LWP;
my $browser = LWP::UserAgent->new;
my $responce = $browser->get("http://google.com");
print $responce->content;
</code></pre>
<p>Your responce object can tell you if it suceeded as well as returning the content of the p... | 1 | 2009-01-07T05:35:48Z | [
"python",
"c",
"text",
"webpage"
] |
Grabbing text from a webpage | 419,260 | <p>I would like to write a program that will find bus stop times and update my personal webpage accordingly.</p>
<p>If I were to do this manually I would </p>
<ol>
<li>Visit www.calgarytransit.com</li>
<li>Enter a stop number. ie) 9510</li>
<li>Click the button "next bus"</li>
</ol>
<p>The results may look like the ... | 2 | 2009-01-07T05:14:40Z | 419,416 | <p>You can use the mechanize library that is available for Python <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">http://wwwsearch.sourceforge.net/mechanize/</a></p>
| 2 | 2009-01-07T06:43:38Z | [
"python",
"c",
"text",
"webpage"
] |
How would a system tray application be accomplished on other platforms? | 419,334 | <p>Windows has the "system tray" that houses the clock and alway-running services like MSN, Steam, etc.</p>
<p>I'd like to develop a wxPython tray application but I'm wondering how well this will port to other platforms. What is the tray equivalent on each platform, and how much manual work would be required to suppo... | 11 | 2009-01-07T05:55:55Z | 419,409 | <p>On Linux it really depends - you got diffrent programming environments there, and some window managers don't even have a tray area. Altho, if you use Gtk (and wx is Gtk really), the <a href="http://www.pygtk.org/docs/pygtk/class-gtkstatusicon.html" rel="nofollow">gtk.StatusIcon</a> is your friend. </p>
<p><a href=... | 1 | 2009-01-07T06:39:42Z | [
"python",
"cross-platform",
"operating-system",
"wxpython",
"system-tray"
] |
How would a system tray application be accomplished on other platforms? | 419,334 | <p>Windows has the "system tray" that houses the clock and alway-running services like MSN, Steam, etc.</p>
<p>I'd like to develop a wxPython tray application but I'm wondering how well this will port to other platforms. What is the tray equivalent on each platform, and how much manual work would be required to suppo... | 11 | 2009-01-07T05:55:55Z | 419,444 | <p>For many Linux desktop systems (Gnome, KDE, etc.) a Freedesktop's <a href="http://standards.freedesktop.org/systemtray-spec/systemtray-spec-latest.html" rel="nofollow">SysTray Protocol</a> is implemented. You can try that if any other solution fails.</p>
| 2 | 2009-01-07T07:00:14Z | [
"python",
"cross-platform",
"operating-system",
"wxpython",
"system-tray"
] |
How would a system tray application be accomplished on other platforms? | 419,334 | <p>Windows has the "system tray" that houses the clock and alway-running services like MSN, Steam, etc.</p>
<p>I'd like to develop a wxPython tray application but I'm wondering how well this will port to other platforms. What is the tray equivalent on each platform, and how much manual work would be required to suppo... | 11 | 2009-01-07T05:55:55Z | 419,446 | <p>wx is a cross-platform GUI and tools library that supports Win32, Mac OS X, GTK+, X11, Motif, WinCE, and more. And if you use it's classes then your application should work on all these platforms.
For system tray look at wxTaskBarIcon (<a href="http://docs.wxwidgets.org/stable/wx_wxtaskbaricon.html#wxtaskbaricon">ht... | 6 | 2009-01-07T07:01:31Z | [
"python",
"cross-platform",
"operating-system",
"wxpython",
"system-tray"
] |
How would a system tray application be accomplished on other platforms? | 419,334 | <p>Windows has the "system tray" that houses the clock and alway-running services like MSN, Steam, etc.</p>
<p>I'd like to develop a wxPython tray application but I'm wondering how well this will port to other platforms. What is the tray equivalent on each platform, and how much manual work would be required to suppo... | 11 | 2009-01-07T05:55:55Z | 419,483 | <p>Under OS X you have the Status Menu bar - the right-most items are often status-related things (like battery status, WiFi connections, etc).</p>
<p>Try searching for <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSStatusBar_Class/Reference/Reference.html" rel="nofollow">NS... | 3 | 2009-01-07T07:34:54Z | [
"python",
"cross-platform",
"operating-system",
"wxpython",
"system-tray"
] |
How would a system tray application be accomplished on other platforms? | 419,334 | <p>Windows has the "system tray" that houses the clock and alway-running services like MSN, Steam, etc.</p>
<p>I'd like to develop a wxPython tray application but I'm wondering how well this will port to other platforms. What is the tray equivalent on each platform, and how much manual work would be required to suppo... | 11 | 2009-01-07T05:55:55Z | 419,824 | <p>Use Qt: <a href="http://doc.trolltech.com/4.2/desktop-systray.html" rel="nofollow">Qt Systray Example</a></p>
<p>That'll show a systray icon on all platforms that Qt runs on and that support such icons. You'll need to come up with a strategy when systray functionality isn't supported, though.</p>
| 1 | 2009-01-07T10:12:14Z | [
"python",
"cross-platform",
"operating-system",
"wxpython",
"system-tray"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 419,389 | <p>You could use a <a href="http://stackoverflow.com/questions/279561/what-is-the-python-equivalent-of-static-variables-inside-a-function">static variable</a>:</p>
<pre><code>def foo(k, v):
foo.a[k] = v
foo.a = {'a': 1, 'b': 2, 'c': 3}
foo('a', 100)
foo('b', 200)
print foo.a
</code></pre>
| 14 | 2009-01-07T06:25:35Z | [
"python",
"variables",
"function-calls"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 419,391 | <p>If 'a' is being created inside the function. It is going out of scope. Simply create it outside the function(and before the function is called). By doing this the list/hash will not be deleted after the program leaves the function.</p>
<pre><code>a = {'a':1,'b':2,'c':3}
# call you funciton here
</code></pre>
| 7 | 2009-01-07T06:26:29Z | [
"python",
"variables",
"function-calls"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 419,924 | <p>You might be talking about a callable object.</p>
<pre><code>class MyFunction( object ):
def __init__( self ):
self.rememberThis= dict()
def __call__( self, arg1, arg2 ):
# do something
rememberThis['a'] = arg1
return someValue
myFunction= MyFunction()
</code></pre>
<p>From... | 14 | 2009-01-07T11:13:21Z | [
"python",
"variables",
"function-calls"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 420,389 | <p>You can 'cheat' using Python's behavior for default arguments. Default arguments are only evaluated once; they get reused for every call of the function.</p>
<pre><code>>>> def testFunction(persistent_dict={'a': 0}):
... persistent_dict['a'] += 1
... print persistent_dict['a']
...
>>> tes... | 3 | 2009-01-07T13:59:00Z | [
"python",
"variables",
"function-calls"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 420,516 | <p>Rather than forcing globals on the code base (that can be the decision of the caller) I prefer the idea of keeping the state related to an instance of the function. A class is good for this but doesn't communicate well what you are trying to accomplish and can be a bit verbose. Taking advantage of closures is, in ... | 5 | 2009-01-07T14:39:05Z | [
"python",
"variables",
"function-calls"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 422,198 | <p>This question doesn't have an elegant answer, in my opinion. The options are callable objects, default values, and attribute hacks. Callable objects are the right answer, but they bring in a lot of structure for what would be a single "static" declaration in another language. Default values are a minor change to t... | 1 | 2009-01-07T21:35:00Z | [
"python",
"variables",
"function-calls"
] |
How to maintain lists and dictionaries between function calls in Python? | 419,379 | <p>I have a function. Inside that I'm maintainfing a dictionary of values.
I want that dictionary to be maintained between different function calls</p>
<p>Suppose the dic is :</p>
<pre><code>a = {'a':1,'b':2,'c':3}
</code></pre>
<p>At first call,say,I changed a[a] to 100
Dict becomes <code>a = {'a':100,'b':2,'c':3}<... | 4 | 2009-01-07T06:21:19Z | 422,756 | <p>Personally, I like the idea of the global statement. It doesn't introduce a global variable but states that a local identifier actually refers to one in the global namespace.</p>
<pre><code>d = dict()
l = list()
def foo(bar, baz):
global d
global l
l.append(bar, baz)
d[bar] = baz
</code></pre>
<p>... | 1 | 2009-01-08T00:26:50Z | [
"python",
"variables",
"function-calls"
] |
Automated Class timetable optimize crawler? | 419,698 | <p><strong>Overall Plan</strong></p>
<p>Get my class information to automatically optimize and select my uni class timetable</p>
<p>Overall Algorithm</p>
<ol>
<li>Logon to the website using its
Enterprise Sign On Engine login</li>
<li>Find my current semester and its
related subjects (pre setup)</li>
<li>Navigate to... | 0 | 2009-01-07T09:24:20Z | 419,741 | <p><a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> was mentioned here a few times, e.g <a href="http://stackoverflow.com/questions/87317/get-list-of-xml-attribute-values-in-python">get-list-of-xml-attribute-values-in-python</a>.</p>
<blockquote>
<p>Beautiful Soup is a Python ... | 0 | 2009-01-07T09:39:56Z | [
"python",
"screen-scraping",
"scheduling"
] |
Automated Class timetable optimize crawler? | 419,698 | <p><strong>Overall Plan</strong></p>
<p>Get my class information to automatically optimize and select my uni class timetable</p>
<p>Overall Algorithm</p>
<ol>
<li>Logon to the website using its
Enterprise Sign On Engine login</li>
<li>Find my current semester and its
related subjects (pre setup)</li>
<li>Navigate to... | 0 | 2009-01-07T09:24:20Z | 419,838 | <p>Depending on how far you plan on taking #6, and how big the dataset is, it may be non-trivial; it certainly smacks of NP-hard global optimisation to me...</p>
<p>Still, if you're talking about tens (rather than hundreds) of nodes, a fairly dumb algorithm should give good enough performance.</p>
<p>So, you have two... | 2 | 2009-01-07T10:29:08Z | [
"python",
"screen-scraping",
"scheduling"
] |
Automated Class timetable optimize crawler? | 419,698 | <p><strong>Overall Plan</strong></p>
<p>Get my class information to automatically optimize and select my uni class timetable</p>
<p>Overall Algorithm</p>
<ol>
<li>Logon to the website using its
Enterprise Sign On Engine login</li>
<li>Find my current semester and its
related subjects (pre setup)</li>
<li>Navigate to... | 0 | 2009-01-07T09:24:20Z | 420,072 | <p>There are waaay too many questions here.</p>
<p>Please break this down into subject areas and ask specific questions on each subject. Please focus on one of these with specific questions. Please define your terms: "best" doesn't mean anything without some specific measurement to optimize.</p>
<p>Here's what I th... | 0 | 2009-01-07T12:09:58Z | [
"python",
"screen-scraping",
"scheduling"
] |
Getting selected value from drop down box in a html form without submit | 419,908 | <p>How to get the text of selected item from a drop down box element in html forms? (using python)
How can I store the value to a variable, when I select one item from the drop down box using mouse? (ie. without using a submit button)</p>
<p>This is for a application which I am doing in app engine which only supports ... | 1 | 2009-01-07T11:05:14Z | 419,947 | <p>Your python code runs on the server (google appengine). HTML form runs on the client (in the browser). The client and the server communicate through HTTP protocol. The client sends <em>requests</em>, and the server responds with <em>responses</em>. You have to send something to the server, to let your python code kn... | 3 | 2009-01-07T11:22:07Z | [
"javascript",
"python",
"html",
"google-app-engine",
"drop-down-menu"
] |
Getting selected value from drop down box in a html form without submit | 419,908 | <p>How to get the text of selected item from a drop down box element in html forms? (using python)
How can I store the value to a variable, when I select one item from the drop down box using mouse? (ie. without using a submit button)</p>
<p>This is for a application which I am doing in app engine which only supports ... | 1 | 2009-01-07T11:05:14Z | 420,004 | <p>Your question shows some misunderstanding on how <a href="http://en.wikipedia.org/wiki/Web_application">web applications</a> work.</p>
<p>The user has to type an address in a browser to get to the application. That sends a request to the server. The server code (written in python) receives this request and has the ... | 19 | 2009-01-07T11:43:06Z | [
"javascript",
"python",
"html",
"google-app-engine",
"drop-down-menu"
] |
Getting selected value from drop down box in a html form without submit | 419,908 | <p>How to get the text of selected item from a drop down box element in html forms? (using python)
How can I store the value to a variable, when I select one item from the drop down box using mouse? (ie. without using a submit button)</p>
<p>This is for a application which I am doing in app engine which only supports ... | 1 | 2009-01-07T11:05:14Z | 420,346 | <p>If you need to send the selected value to your server without submiting, I think that the best (if not the only one) aproach would be to use some ajax. </p>
<p>If you are using jQuery, have a look at <a href="http://docs.jquery.com/Ajax." rel="nofollow">it's ajax stuff.</a> and it's <a href="http://docs.jquery.com/... | 1 | 2009-01-07T13:42:55Z | [
"javascript",
"python",
"html",
"google-app-engine",
"drop-down-menu"
] |
Getting selected value from drop down box in a html form without submit | 419,908 | <p>How to get the text of selected item from a drop down box element in html forms? (using python)
How can I store the value to a variable, when I select one item from the drop down box using mouse? (ie. without using a submit button)</p>
<p>This is for a application which I am doing in app engine which only supports ... | 1 | 2009-01-07T11:05:14Z | 7,284,763 | <p>The problem with using onchange is that not all users are using a mouse. If you have a combo-box and change the value with the keyboard, you'd never be able to get past the first value without the form submitting.</p>
<p>~Cyrix</p>
| 0 | 2011-09-02T14:14:07Z | [
"javascript",
"python",
"html",
"google-app-engine",
"drop-down-menu"
] |
python install on leopard | 420,515 | <p>I'll admit I'm completely dumbed by python install. Can someone help me on how to install module</p>
<p>I want to play with PyGame, PyOpenGL etc. So I install them, but I everytime I type "import pygame" error message shows up.</p>
<p>here's my environment so far.</p>
<p>In .bash_profile</p>
<pre><code>PATH=${PA... | 1 | 2009-01-07T14:38:58Z | 420,543 | <p>I'm not a huge fan of the default python install on OS X in the first place, mostly because it's usually a pretty old version. I find everything works better if I use the macports package.</p>
<p>easy_install seems to work better with the macports package, but maybe that's just because I'm too lazy to figure out al... | 1 | 2009-01-07T14:43:59Z | [
"python",
"osx",
"osx-leopard",
"easy-install"
] |
python install on leopard | 420,515 | <p>I'll admit I'm completely dumbed by python install. Can someone help me on how to install module</p>
<p>I want to play with PyGame, PyOpenGL etc. So I install them, but I everytime I type "import pygame" error message shows up.</p>
<p>here's my environment so far.</p>
<p>In .bash_profile</p>
<pre><code>PATH=${PA... | 1 | 2009-01-07T14:38:58Z | 420,628 | <p>See <a href="http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/" rel="nofollow">http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/</a></p>
| 0 | 2009-01-07T15:04:20Z | [
"python",
"osx",
"osx-leopard",
"easy-install"
] |
Migrating from CPython to Jython | 420,792 | <p>I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. </p>
<p>Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?</p>
<p>From reading the <a href="http... | 23 | 2009-01-07T15:46:10Z | 421,125 | <p>So far, I have noticed two further issues:</p>
<ul>
<li>String interning 'a' is 'a' is not guaranteed (and it is just an implementation fluke on CPython). This could be a serious problem, and really was in one of the libraries I was porting (Jinja2). Unit tests are (as always) your best friends!</li>
</ul>
<pre>
J... | 7 | 2009-01-07T17:01:35Z | [
"python",
"migration",
"jython",
"cpython"
] |
Migrating from CPython to Jython | 420,792 | <p>I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. </p>
<p>Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?</p>
<p>From reading the <a href="http... | 23 | 2009-01-07T15:46:10Z | 847,629 | <p>When I switched a project from CPython to Jython some time ago I realized a speed-down of up to 50x for time-critical sections. Because of that I stayed with CPython. </p>
<p>However, that might have changed now with the current versions. </p>
| 2 | 2009-05-11T11:03:51Z | [
"python",
"migration",
"jython",
"cpython"
] |
Migrating from CPython to Jython | 420,792 | <p>I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. </p>
<p>Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?</p>
<p>From reading the <a href="http... | 23 | 2009-01-07T15:46:10Z | 2,578,481 | <p>First off, I have to say the Jython implementation is very good. Most things "just work". </p>
<p>Here are a few things that I have encountered:</p>
<ul>
<li><p>C modules are not available, of course. </p></li>
<li><p>open('file').read() doesn't automatically close the file. This has to do with the difference in t... | 9 | 2010-04-05T13:03:03Z | [
"python",
"migration",
"jython",
"cpython"
] |
Migrating from CPython to Jython | 420,792 | <p>I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. </p>
<p>Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?</p>
<p>From reading the <a href="http... | 23 | 2009-01-07T15:46:10Z | 2,578,509 | <p>You might also want to research <a href="http://jpype.sourceforge.net/" rel="nofollow">JPype</a>. I'm not sure how mature it is compared to Jython, but it should allow CPython to access Java code.</p>
| 2 | 2010-04-05T13:10:55Z | [
"python",
"migration",
"jython",
"cpython"
] |
Migrating from CPython to Jython | 420,792 | <p>I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. </p>
<p>Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?</p>
<p>From reading the <a href="http... | 23 | 2009-01-07T15:46:10Z | 4,465,539 | <p>Recently, I worked on a project for a professor at my school with a group. Early on, it was decided that we would write the project in Python. We definitely should have used CPython. We wrote the program in Python and all of our unit tests eventually worked. Because most people already have Java installed on the... | 1 | 2010-12-16T21:28:04Z | [
"python",
"migration",
"jython",
"cpython"
] |
Migrating from CPython to Jython | 420,792 | <p>I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. </p>
<p>Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?</p>
<p>From reading the <a href="http... | 23 | 2009-01-07T15:46:10Z | 4,482,032 | <p>I'm starting this as a wiki collected from the other answers and my experience. Feel free to edit and add stuff, but please try to stick to practical advice rather than a list of broken things. Here's an <a href="http://jython.sourceforge.net/archive/21/docs/differences.html" rel="nofollow">old list of differences</... | 4 | 2010-12-19T07:31:54Z | [
"python",
"migration",
"jython",
"cpython"
] |
python setup.py develop not updating easy_install.pth | 421,050 | <p>According to <a href="http://peak.telecommunity.com/DevCenter/setuptools#development-mode" rel="nofollow">setuptools</a> documentation, setup.py develop is supposed to create the egg-link file and update easy_install.pth when installing into site-packages folder. However, in my case it's only creating the egg-link ... | 6 | 2009-01-07T16:43:28Z | 494,887 | <p>I'd try to debug it with pdb. The issue is most likely with the easy install's method check_site_dir, which seeks for easy-install.pth. </p>
| 0 | 2009-01-30T08:38:39Z | [
"python",
"setuptools"
] |
python setup.py develop not updating easy_install.pth | 421,050 | <p>According to <a href="http://peak.telecommunity.com/DevCenter/setuptools#development-mode" rel="nofollow">setuptools</a> documentation, setup.py develop is supposed to create the egg-link file and update easy_install.pth when installing into site-packages folder. However, in my case it's only creating the egg-link ... | 6 | 2009-01-07T16:43:28Z | 495,822 | <p>Reinstall setuptools with the command <code>easy_install --always-unzip --upgrade setuptools</code>. If that fixes it then the zipping was the problem.</p>
| 3 | 2009-01-30T15:06:09Z | [
"python",
"setuptools"
] |
How do I enable push-notification for IMAP (Gmail) using Python imaplib? | 421,178 | <p>Is there a way to monitor a gmail account using imaplib without polling gmail each time I want to see if there is new mail. Or in other words, I just want the script to be notified of a new message so I can process it right away instead of any lag time between polls.</p>
<p>I see that the IMAP protocol supports thi... | 24 | 2009-01-07T17:13:32Z | 421,343 | <p>There isn't something in imaplib that does this, AFAIK (disclamer: I know very little about Python), however, it seems that someone has implemented an IDLE extension for Python which has the same interface as imaplib (which you can swap out with no changes to existing code, apparently):</p>
<p><a href="http://www.c... | 13 | 2009-01-07T18:04:46Z | [
"python",
"gmail",
"imap"
] |
How do I enable push-notification for IMAP (Gmail) using Python imaplib? | 421,178 | <p>Is there a way to monitor a gmail account using imaplib without polling gmail each time I want to see if there is new mail. Or in other words, I just want the script to be notified of a new message so I can process it right away instead of any lag time between polls.</p>
<p>I see that the IMAP protocol supports thi... | 24 | 2009-01-07T17:13:32Z | 442,129 | <p>Check out <a href="http://packages.python.org/ProcImap/" rel="nofollow">ProcImap</a>. It's a more abstract framework on top of libimap and libimap2, providing a nice solution to handle IMAP services. Looks like just the stuff you are looking for, and for me as well. I'm right having the same problem with you and jus... | 6 | 2009-01-14T06:44:40Z | [
"python",
"gmail",
"imap"
] |
How do I enable push-notification for IMAP (Gmail) using Python imaplib? | 421,178 | <p>Is there a way to monitor a gmail account using imaplib without polling gmail each time I want to see if there is new mail. Or in other words, I just want the script to be notified of a new message so I can process it right away instead of any lag time between polls.</p>
<p>I see that the IMAP protocol supports thi... | 24 | 2009-01-07T17:13:32Z | 4,833,192 | <p>This link shows an example of using IMAP IDLE: <a href="http://blog.timstoop.nl/2009/03/11/python-imap-idle-with-imaplib2/" rel="nofollow">http://blog.timstoop.nl/2009/03/11/python-imap-idle-with-imaplib2/</a></p>
<p>It uses the same library linked to in casperOne's answer (imaplib2).</p>
| 2 | 2011-01-28T21:23:28Z | [
"python",
"gmail",
"imap"
] |
How do I enable push-notification for IMAP (Gmail) using Python imaplib? | 421,178 | <p>Is there a way to monitor a gmail account using imaplib without polling gmail each time I want to see if there is new mail. Or in other words, I just want the script to be notified of a new message so I can process it right away instead of any lag time between polls.</p>
<p>I see that the IMAP protocol supports thi... | 24 | 2009-01-07T17:13:32Z | 16,112,967 | <p>There is simple <a href="http://bugs.python.org/file27400/imapidle.patch" rel="nofollow">patch</a> proposed at <a href="http://bugs.python.org/issue11245" rel="nofollow">bugs.python.org</a> implementing <a href="http://tools.ietf.org/html/rfc2177" rel="nofollow">RFC 2177 IMAP IDLE</a> command in a synchronous way ( ... | 2 | 2013-04-19T20:26:11Z | [
"python",
"gmail",
"imap"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,228 | <pre><code>import subprocess
p=subprocess.Popen(args, stdout=subprocess.PIPE)
print p.communicate()[0]
</code></pre>
<p>It would look pretty much the same. But the path should not be r'"whatever the path is"'. Because that gives me an error. You want "the path with escaped backslashes" or r'the path without escapin... | 5 | 2009-01-07T17:31:02Z | [
"python",
"syntax",
"scripting",
"process"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,269 | <p>Remove quotes from the name of the executable. On the first line of your example, instead of</p>
<pre><code>sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
</code></pre>
<p>use:</p>
<pre><code>sqlpubwiz = r'C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwi... | 4 | 2009-01-07T17:44:36Z | [
"python",
"syntax",
"scripting",
"process"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,367 | <p>Please remember that os.system uses the shell, and so you must really pass</p>
<pre><code>shell=True
</code></pre>
<p>to the Popen constructor/call to emulate it properly. You may not actually need a shell, of course, but there it is.</p>
| -1 | 2009-01-07T18:11:02Z | [
"python",
"syntax",
"scripting",
"process"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,421 | <p>This isnt an answer directly to your question but I thought it might be helpful.</p>
<p>In case you ever want more granular control over what is returned for exception handling etc, you can also check out <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow"><strong>pexpect</strong></a>. I have used it in situa... | 0 | 2009-01-07T18:22:03Z | [
"python",
"syntax",
"scripting",
"process"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,470 | <p>Below is my revised code based on <a href="http://stackoverflow.com/questions/421206/in-python-how-i-do-use-subprocess-instead-of-os-system#421228">Carlos Rendon</a> (and <a href="http://stackoverflow.com/questions/421206/in-python-how-i-do-use-subprocess-instead-of-os-system#421269">nosklo</a>) help and suggestions... | 4 | 2009-01-07T18:31:59Z | [
"python",
"syntax",
"scripting",
"process"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,768 | <p>FYI, <code>subprocess</code> has a <code>list2cmdline()</code> function that will let you see the string that <code>Popen</code> will be using.</p>
<p>Your version gives:</p>
<pre><code>'"C:\\Program Files\\Microsoft SQL Server\\90\\Tools\\Publishing\\sqlpubwiz.exe" script "-C server=myLocalServer;database=myLocal... | 4 | 2009-01-07T19:41:10Z | [
"python",
"syntax",
"scripting",
"process"
] |
In Python, how I do use subprocess instead of os.system? | 421,206 | <p>I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"):</p>
<pre><code>import os
sqlpubwiz = r'"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz.exe"'
server = 'myLocal... | 3 | 2009-01-07T17:24:50Z | 421,830 | <p>Windows commands will accept forward slashes '/' in place of backslashes in pathnames, so you can use the former to avoid escaping backslashes in your command strings. Not exactly an answer to your question, but perhaps useful to know.</p>
| 0 | 2009-01-07T19:55:04Z | [
"python",
"syntax",
"scripting",
"process"
] |
Running unexported .dll functions with python | 421,223 | <p>This may seem like a weird question, but I would like to know how I can run a function in a .dll from a memory 'signature'. I don't understand much about how it actually works, but I needed it badly. Its a way of running unexported functions from within a .dll, if you know the memory signature and adress of it.
For ... | 5 | 2009-01-07T17:30:21Z | 430,523 | <p>If you can already run them using C++ then you can try using SWIG to generate python wrappers for the C++ code you've written making it callable from python.</p>
<p><a href="http://www.swig.org/" rel="nofollow">http://www.swig.org/</a></p>
<p>Some caveats that I've found using SWIG:</p>
<p>Swig looks up types bas... | 2 | 2009-01-10T03:45:30Z | [
"python",
"memory",
"ctypes"
] |
Running unexported .dll functions with python | 421,223 | <p>This may seem like a weird question, but I would like to know how I can run a function in a .dll from a memory 'signature'. I don't understand much about how it actually works, but I needed it badly. Its a way of running unexported functions from within a .dll, if you know the memory signature and adress of it.
For ... | 5 | 2009-01-07T17:30:21Z | 484,905 | <p>You said you were trying to call a function that was not exported; as far as I know, that's not possible from Python. However, your problem seems to be merely that the name is mangled.</p>
<p>You can invoke an arbitrary export using ctypes. Since the name is mangled, and isn't a valid Python identifier, you can ... | 0 | 2009-01-27T19:41:12Z | [
"python",
"memory",
"ctypes"
] |
Python script to list users and groups | 421,618 | <p>I'm attempting to code a script that outputs each user and their group on their own line like so:</p>
<pre><code>user1 group1
user2 group1
user3 group2
...
user10 group6
</code></pre>
<p>etc. </p>
<p>I'm writing up a script in python for this but was wondering how SO might do this. Thanks!</p>
<p>p.s. T... | 15 | 2009-01-07T19:05:11Z | 421,651 | <p>the <code>grp</code> module is your friend. Look at <code>grp.getgrall()</code> to get a list of all groups and their members.</p>
<p><strong>EDIT</strong> example:</p>
<pre><code>import grp
groups = grp.getgrall()
for group in groups:
for user in group[3]:
print user, group[0]
</code></pre>
| 13 | 2009-01-07T19:12:27Z | [
"python",
"scripting",
"sysadmin",
"user",
"groups"
] |
Python script to list users and groups | 421,618 | <p>I'm attempting to code a script that outputs each user and their group on their own line like so:</p>
<pre><code>user1 group1
user2 group1
user3 group2
...
user10 group6
</code></pre>
<p>etc. </p>
<p>I'm writing up a script in python for this but was wondering how SO might do this. Thanks!</p>
<p>p.s. T... | 15 | 2009-01-07T19:05:11Z | 421,670 | <p>For *nix, you have the <a href="http://docs.python.org/2/library/pwd.html" rel="nofollow">pwd</a> and <a href="http://docs.python.org/2/library/grp.html" rel="nofollow">grp</a> modules. You iterate through <code>pwd.getpwall()</code> to get all users. You look up their group names with <code>grp.getgrgid(gid)</cod... | 13 | 2009-01-07T19:14:47Z | [
"python",
"scripting",
"sysadmin",
"user",
"groups"
] |
Python script to list users and groups | 421,618 | <p>I'm attempting to code a script that outputs each user and their group on their own line like so:</p>
<pre><code>user1 group1
user2 group1
user3 group2
...
user10 group6
</code></pre>
<p>etc. </p>
<p>I'm writing up a script in python for this but was wondering how SO might do this. Thanks!</p>
<p>p.s. T... | 15 | 2009-01-07T19:05:11Z | 421,686 | <p>sh/bash:</p>
<pre><code>getent passwd | cut -f1 -d: | while read name; do echo -n "$name " ; groups $name ; done
</code></pre>
| 4 | 2009-01-07T19:19:11Z | [
"python",
"scripting",
"sysadmin",
"user",
"groups"
] |
Python script to list users and groups | 421,618 | <p>I'm attempting to code a script that outputs each user and their group on their own line like so:</p>
<pre><code>user1 group1
user2 group1
user3 group2
...
user10 group6
</code></pre>
<p>etc. </p>
<p>I'm writing up a script in python for this but was wondering how SO might do this. Thanks!</p>
<p>p.s. T... | 15 | 2009-01-07T19:05:11Z | 33,488,392 | <p>Fed to os.popen or whatever....</p>
<p>"man groups" </p>
<p>GROUPS(1) User Commands GROUPS(1)</p>
<p>NAME
groups - print the groups a user is in</p>
<p>SYNOPSIS
groups [OPTION]... [USERNAME]...</p... | -2 | 2015-11-02T22:43:36Z | [
"python",
"scripting",
"sysadmin",
"user",
"groups"
] |
Python script to list users and groups | 421,618 | <p>I'm attempting to code a script that outputs each user and their group on their own line like so:</p>
<pre><code>user1 group1
user2 group1
user3 group2
...
user10 group6
</code></pre>
<p>etc. </p>
<p>I'm writing up a script in python for this but was wondering how SO might do this. Thanks!</p>
<p>p.s. T... | 15 | 2009-01-07T19:05:11Z | 36,508,787 | <p>I believe that this code meets your need.</p>
<p>Basically, a simple function which is capable to deal with the structure of any one of these files (/etc/passwd and /etc/group).</p>
<p>Just have to open each file and call the same function for both.</p>
<p>P.S: This function works for both of them, because each f... | 0 | 2016-04-08T20:29:40Z | [
"python",
"scripting",
"sysadmin",
"user",
"groups"
] |
How can the user communicate with my python script using the shell? | 422,091 | <p>How can I implement the following in python?</p>
<pre><code>#include <iostream>
int main() {
std::string a;
std::cout << "What is your name? ";
std::cin >> a;
std::cout << std::endl << "You said: " << a << std::endl;
}
</code></pre>
<p>Output:</p>
<blockqu... | 3 | 2009-01-07T21:07:23Z | 422,105 | <p>Look at the <code>print</code> statement and the <code>raw_input()</code> function.</p>
<p>Or look at <code>sys.stdin.read()</code> and <code>sys.stdout.write()</code>. </p>
<p>When using <code>sys.stdout</code>, don't forget to flush.</p>
| 3 | 2009-01-07T21:09:19Z | [
"python"
] |
How can the user communicate with my python script using the shell? | 422,091 | <p>How can I implement the following in python?</p>
<pre><code>#include <iostream>
int main() {
std::string a;
std::cout << "What is your name? ";
std::cin >> a;
std::cout << std::endl << "You said: " << a << std::endl;
}
</code></pre>
<p>Output:</p>
<blockqu... | 3 | 2009-01-07T21:07:23Z | 422,121 | <p>Call </p>
<pre><code>name = raw_input('What is your name?')
</code></pre>
<p>and </p>
<pre><code>print 'You said', name
</code></pre>
| 7 | 2009-01-07T21:14:14Z | [
"python"
] |
How can the user communicate with my python script using the shell? | 422,091 | <p>How can I implement the following in python?</p>
<pre><code>#include <iostream>
int main() {
std::string a;
std::cout << "What is your name? ";
std::cin >> a;
std::cout << std::endl << "You said: " << a << std::endl;
}
</code></pre>
<p>Output:</p>
<blockqu... | 3 | 2009-01-07T21:07:23Z | 422,157 | <pre><code>print "You said:", raw_input("What is your name? ")
</code></pre>
<p>EDIT: as Swaroop mentioned, this doesn't work (I'm guessing <code>raw_input</code> flushes stdout)</p>
| 3 | 2009-01-07T21:25:01Z | [
"python"
] |
How can the user communicate with my python script using the shell? | 422,091 | <p>How can I implement the following in python?</p>
<pre><code>#include <iostream>
int main() {
std::string a;
std::cout << "What is your name? ";
std::cin >> a;
std::cout << std::endl << "You said: " << a << std::endl;
}
</code></pre>
<p>Output:</p>
<blockqu... | 3 | 2009-01-07T21:07:23Z | 422,733 | <p>The simplest way for python 2.x is</p>
<pre><code>var = raw_input()
print var
</code></pre>
<p>Another way is using the input() function; n.b. input(), unlike raw_input() expects the input to be a valid python expression. In most cases you should raw_input() and validate it first. You can also use</p>
<pre><co... | 1 | 2009-01-08T00:14:53Z | [
"python"
] |
How to access the user profile in a Django template? | 422,140 | <p>I'm storing some additional per-user information using the <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users"><code>AUTH_PROFILE_MODULE</code></a>.</p>
<p>We can access the user in a Django template using <code>{{ request.user }}</code> but how do we access fields... | 72 | 2009-01-07T21:19:13Z | 422,153 | <p>Use <code>{{ request.user.get_profile.whatever }}</code>. Django's templating language automatically calls things that are callable - in this case, the <code>.get_profile()</code> method.</p>
| 119 | 2009-01-07T21:24:09Z | [
"python",
"django",
"django-templates"
] |
How to access the user profile in a Django template? | 422,140 | <p>I'm storing some additional per-user information using the <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users"><code>AUTH_PROFILE_MODULE</code></a>.</p>
<p>We can access the user in a Django template using <code>{{ request.user }}</code> but how do we access fields... | 72 | 2009-01-07T21:19:13Z | 422,218 | <p>Yes it is possible to access profile from template using
request.user.get_profile</p>
<p>However there is a small <b>caveat</b>: not all users will have profiles, which was in my case with admin users. So calling directly
<code>{{ request.user.get_profile.whatever }}</code> from the template will cause an er... | 7 | 2009-01-07T21:41:55Z | [
"python",
"django",
"django-templates"
] |
How to access the user profile in a Django template? | 422,140 | <p>I'm storing some additional per-user information using the <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users"><code>AUTH_PROFILE_MODULE</code></a>.</p>
<p>We can access the user in a Django template using <code>{{ request.user }}</code> but how do we access fields... | 72 | 2009-01-07T21:19:13Z | 2,118,943 | <p>Not sure why it's different for me, but I need to use {{user}} rather than {{request.user}}.</p>
| 17 | 2010-01-22T17:00:28Z | [
"python",
"django",
"django-templates"
] |
How to access the user profile in a Django template? | 422,140 | <p>I'm storing some additional per-user information using the <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users"><code>AUTH_PROFILE_MODULE</code></a>.</p>
<p>We can access the user in a Django template using <code>{{ request.user }}</code> but how do we access fields... | 72 | 2009-01-07T21:19:13Z | 36,241,677 | <p>if you using Django > 1.5 </p>
<ol>
<li>remove AUTH_PROFILE_MODULE = 'myapp.profile' form setting.py. </li>
<li>use models.OneToOneField(User) in your Profile Class. </li>
<li>then you can't use {{ request.user.profile.whatever }}</li>
</ol>
| 0 | 2016-03-26T22:33:24Z | [
"python",
"django",
"django-templates"
] |
Fixed-point arithmetic | 422,247 | <p>Does anyone know of a library to do fixed point arithmetic in Python?
Or, does anyone has sample code?</p>
| 3 | 2009-01-07T21:48:13Z | 422,318 | <p>If you are interested in doing fixed point arithmetic, the Python Standard Library has a <a href="http://docs.python.org/library/decimal.html">decimal</a> module that can do it. </p>
<p>Actually, it has a more flexible floating point ability than the built-in too. By flexible I mean that it: </p>
<ul>
<li><p>Has... | 8 | 2009-01-07T22:00:42Z | [
"python",
"math"
] |
Fixed-point arithmetic | 422,247 | <p>Does anyone know of a library to do fixed point arithmetic in Python?
Or, does anyone has sample code?</p>
| 3 | 2009-01-07T21:48:13Z | 4,474,302 | <p>The <a href="http://www.dilloneng.com/demodel.html" rel="nofollow">deModel</a> package sounds like what you're looking for.</p>
| 2 | 2010-12-17T19:57:35Z | [
"python",
"math"
] |
Drawing with Webdings in PIL | 422,555 | <p>I've got a Python program using PIL to render text, and it works great with all kinds of fonts. But it only draws "missing glyph" rectangles with wingdings or webdings.</p>
<p>Here's a sample that tries to draw every unicode character:</p>
<pre><code># Run this with .ttf file path as an argument, and also an enco... | 2 | 2009-01-07T23:05:58Z | 422,630 | <p>I must have done something wrong before. "symb" as the encoding works for wingdings too! Sorry for the noise...</p>
| 1 | 2009-01-07T23:33:28Z | [
"python",
"fonts",
"python-imaging-library"
] |
Drawing with Webdings in PIL | 422,555 | <p>I've got a Python program using PIL to render text, and it works great with all kinds of fonts. But it only draws "missing glyph" rectangles with wingdings or webdings.</p>
<p>Here's a sample that tries to draw every unicode character:</p>
<pre><code># Run this with .ttf file path as an argument, and also an enco... | 2 | 2009-01-07T23:05:58Z | 422,658 | <p>Not all of wingdings is mapped to unicode: see <a href="http://www.alanwood.net/demos/wingdings.html" rel="nofollow">http://www.alanwood.net/demos/wingdings.html</a></p>
<p>Also you're only covering the <a href="http://www.j-a-b.net/web/char/char-unicode-bmp?characterRange=9984X10175" rel="nofollow">Basic Multiling... | 1 | 2009-01-07T23:41:44Z | [
"python",
"fonts",
"python-imaging-library"
] |
How to get the "python setup.py" submits informations on freshmeat? | 422,717 | <p>With this you can easily submit the information about your software on pypi:</p>
<pre><code>python setup.py register
</code></pre>
<p>But there is not a similar command for submitting information to freshmeat.
How could I write a distutils.Command that let me do the following.</p>
<pre><code>python setup.py fresh... | 1 | 2009-01-08T00:09:01Z | 1,000,676 | <p>It should be fairly easy; I'd say freshmeat API will be straightforward.</p>
<p>For python site, for setup() function in setup.py, give this argument:</p>
<pre><code>entry_points = {
'distutils.commands' : [
'freshmeat-submit = freshsubmitter.submit:SubmitToFreshMeat',
],
},
</code></pre>
<p>where... | 0 | 2009-06-16T10:28:09Z | [
"python",
"setuptools"
] |
What's the most pythonic way of access C libraries - for example, OpenSSL? | 422,903 | <p>I need to access the crypto functions of OpenSSL to encode Blowfish data in a CBC streams. I've googled and found some Blowfish libraries (hand written) and some OpenSSL wrappers (none of the seem complete.)</p>
<p>In the end, I need to access the certain OpenSSL functions, such as the full blowfish.h library of <a... | 3 | 2009-01-08T01:31:35Z | 422,941 | <p><a href="http://docs.python.org/library/ctypes.html" rel="nofollow">ctypes</a> is the place to start. It lets you call into DLLs, using C-declared types, etc. I don't know if there are limitations that will keep you from doing everything you need, but it's very capable, and it's included in the standard library.</... | 5 | 2009-01-08T01:48:17Z | [
"c",
"encryption",
"openssl",
"python"
] |
What's the most pythonic way of access C libraries - for example, OpenSSL? | 422,903 | <p>I need to access the crypto functions of OpenSSL to encode Blowfish data in a CBC streams. I've googled and found some Blowfish libraries (hand written) and some OpenSSL wrappers (none of the seem complete.)</p>
<p>In the end, I need to access the certain OpenSSL functions, such as the full blowfish.h library of <a... | 3 | 2009-01-08T01:31:35Z | 422,964 | <p>SWIG is pretty much the canonical method. Works good, too.</p>
| 0 | 2009-01-08T01:59:23Z | [
"c",
"encryption",
"openssl",
"python"
] |
What's the most pythonic way of access C libraries - for example, OpenSSL? | 422,903 | <p>I need to access the crypto functions of OpenSSL to encode Blowfish data in a CBC streams. I've googled and found some Blowfish libraries (hand written) and some OpenSSL wrappers (none of the seem complete.)</p>
<p>In the end, I need to access the certain OpenSSL functions, such as the full blowfish.h library of <a... | 3 | 2009-01-08T01:31:35Z | 423,117 | <p>There's lots of ways to interface with C (and C++) in Python. ctypes is pretty nice for quick little extensions, but it has a habit of turning would be compile time errors into runtime segfaults. If you're looking to write your own extension, SIP is very nice. SWIG is very general, but has a larger following. Of cou... | 5 | 2009-01-08T03:08:23Z | [
"c",
"encryption",
"openssl",
"python"
] |
What's the most pythonic way of access C libraries - for example, OpenSSL? | 422,903 | <p>I need to access the crypto functions of OpenSSL to encode Blowfish data in a CBC streams. I've googled and found some Blowfish libraries (hand written) and some OpenSSL wrappers (none of the seem complete.)</p>
<p>In the end, I need to access the certain OpenSSL functions, such as the full blowfish.h library of <a... | 3 | 2009-01-08T01:31:35Z | 429,626 | <p>I've had good success with Cython, as well.</p>
| 0 | 2009-01-09T20:37:31Z | [
"c",
"encryption",
"openssl",
"python"
] |
What's the most pythonic way of access C libraries - for example, OpenSSL? | 422,903 | <p>I need to access the crypto functions of OpenSSL to encode Blowfish data in a CBC streams. I've googled and found some Blowfish libraries (hand written) and some OpenSSL wrappers (none of the seem complete.)</p>
<p>In the end, I need to access the certain OpenSSL functions, such as the full blowfish.h library of <a... | 3 | 2009-01-08T01:31:35Z | 521,542 | <p>I was happy with M2Crypto (an OpenSSL wrapper) for blowfish.</p>
<pre><code>import M2Crypto
from M2Crypto import EVP
import base64
import struct
key = '0' * 16 # security FTW
iv = '' # initialization vector FTW
dummy_block = ' ' * 8
encrypt = EVP.Cipher('bf_cbc', key, iv, M2Crypto.encrypt)
decrypt = EVP.Cipher('... | 5 | 2009-02-06T18:27:35Z | [
"c",
"encryption",
"openssl",
"python"
] |
What's the most pythonic way of access C libraries - for example, OpenSSL? | 422,903 | <p>I need to access the crypto functions of OpenSSL to encode Blowfish data in a CBC streams. I've googled and found some Blowfish libraries (hand written) and some OpenSSL wrappers (none of the seem complete.)</p>
<p>In the end, I need to access the certain OpenSSL functions, such as the full blowfish.h library of <a... | 3 | 2009-01-08T01:31:35Z | 522,741 | <p>I would recommend <a href="http://chandlerproject.org/Projects/MeTooCrypto" rel="nofollow">M2Crypto</a> as well, but if the code sample by joeforker looks a bit strange you might have an easier time understanding the M2Crypto cipher unit tests, which include Blowfish. Check out the CipherTestCase in <a href="http://... | 0 | 2009-02-07T00:11:19Z | [
"c",
"encryption",
"openssl",
"python"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 423,401 | <p>You may want to explore the notion of <a href="http://docs.python.org/reference/datamodel.html">namespaces</a>. In Python, the <a href="http://docs.python.org/tutorial/modules.html">module</a> is the natural place for <em>global</em> data:</p>
<blockquote>
<p>Each module has its own private symbol table, which is... | 129 | 2009-01-08T05:59:04Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 423,596 | <p>You can use a global variable in other functions by declaring it as <code>global</code> in each function that assigns to it:</p>
<pre><code>globvar = 0
def set_globvar_to_one():
global globvar # Needed to modify global copy of globvar
globvar = 1
def print_globvar():
print globvar # No need for... | 2,407 | 2009-01-08T08:39:44Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 423,641 | <p>If you want to refer to global variable in a function, you can use <strong>global</strong> keyword to declare which variables are global. You don't have to use it in all cases (as someone here incorrectly claims) - if the name referenced in an expression cannot be found in local scope or scopes in the functions in w... | 28 | 2009-01-08T09:03:33Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 423,668 | <p>If I'm understanding your situation correctly, what you're seeing is the result of how Python handles local (function) and global (module) namespaces.</p>
<p>Say you've got a module like this:</p>
<pre><code># sample.py
myGlobal = 5
def func1():
myGlobal = 42
def func2():
print myGlobal
func1()
func2()
... | 519 | 2009-01-08T09:19:55Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 427,818 | <p>You're not actually storing the global in a local variable, just creating a local reference to the same object that your original global reference refers to. Remember that pretty much everything in Python is a name referring to an object, and nothing gets copied in usual operation.</p>
<p>If you didn't have to expl... | 11 | 2009-01-09T11:56:19Z | [
"python",
"global-variables",
"scope"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.