Q_Id int64 337 49.3M | CreationDate stringlengths 23 23 | Users Score int64 -42 1.15k | Other int64 0 1 | Python Basics and Environment int64 0 1 | System Administration and DevOps int64 0 1 | Tags stringlengths 6 105 | A_Id int64 518 72.5M | AnswerCount int64 1 64 | is_accepted bool 2
classes | Web Development int64 0 1 | GUI and Desktop Applications int64 0 1 | Answer stringlengths 6 11.6k | Available Count int64 1 31 | Q_Score int64 0 6.79k | Data Science and Machine Learning int64 0 1 | Question stringlengths 15 29k | Title stringlengths 11 150 | Score float64 -1 1.2 | Database and SQL int64 0 1 | Networking and APIs int64 0 1 | ViewCount int64 8 6.81M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5,491,851 | 2011-03-30T20:19:00.000 | 4 | 0 | 1 | 0 | python,couchdb | 5,498,961 | 1 | true | 0 | 0 | I just added show/list support to couchdb-python. Any problems, please use the mailing list. | 1 | 2 | 0 | The python-couchdb package ( used as import couchdb ) provides a db.view() function to access a couchdb "_view", but how do you access a "_show" or "_list" function? | CouchDB and Python: how to use "_show" and "_list" functions? | 1.2 | 0 | 0 | 429 |
5,492,158 | 2011-03-30T20:44:00.000 | 0 | 0 | 1 | 0 | python,printing | 5,492,182 | 5 | false | 0 | 0 | If you're on a xterm-like output device, the way you do this is by OVERWRITING the output. You have to ensure that when you write the number you end with a carriage-return (without a newline), which moves the cursor back to the start of the line without advancing to the next line. The next output you write will repla... | 2 | 7 | 0 | How can I edit a string that I just printed? For example, for a countdown counter (First prints 30, then changes it to 29 and so on)
Thanks. | How can I edit a string that was printed to stdout? | 0 | 0 | 0 | 3,650 |
5,492,158 | 2011-03-30T20:44:00.000 | 0 | 0 | 1 | 0 | python,printing | 5,492,197 | 5 | false | 0 | 0 | You can not change what you printed. What's printed is printed. But, like bradley.ayers said you can return to the beginning of the line and print something new over the old value. | 2 | 7 | 0 | How can I edit a string that I just printed? For example, for a countdown counter (First prints 30, then changes it to 29 and so on)
Thanks. | How can I edit a string that was printed to stdout? | 0 | 0 | 0 | 3,650 |
5,493,565 | 2011-03-30T23:10:00.000 | 0 | 0 | 0 | 0 | python,nlp,nltk,wordnet | 5,494,360 | 2 | false | 0 | 0 | You could try using some of the similarity functions with handpicked synsets, and use that to filter. But it's essentially the same as following the hypernym tree - afaik all the wordnet similarity functions use hypernym distance in their calculations. Also, there's a lot of optional attributes of a synset that might b... | 1 | 7 | 1 | Is there a way to capture WordNet selectional restrictions (such as +animate, +human, etc.) from synsets through NLTK?
Or is there any other way of providing semantic information about synset? The closest I could get to it were hypernym relations. | Wordnet selectional restrictions in NLTK | 0 | 0 | 0 | 820 |
5,495,203 | 2011-03-31T04:01:00.000 | 0 | 0 | 1 | 0 | python-3.x,multiprocessing | 5,497,033 | 3 | false | 0 | 0 | You are somehow creating a lot of processes. This can be done by the
os.system(), os.popen*(), os.spawn*() or methods in the popen2, subprocess and multiprocessing libraries.
If you aren't using CPython but another Python implementation such as Jython or Stackless, you can also use up many cores by threading.
You'll ha... | 1 | 4 | 0 | I have a fairly memory expensive Python program to run on a computer that has 8 CPUs (using Python 3.1 64 bit). The problem is that it uses all 8 processors to 100% usage and thus freezes the machine and makes things slow. How would I make Python use only 7 of the processors to free up more CPU? I have experimented wit... | How to limit the number of processors that Python uses | 0 | 0 | 0 | 6,394 |
5,496,253 | 2011-03-31T06:55:00.000 | 0 | 0 | 0 | 0 | python | 5,496,296 | 1 | true | 0 | 0 | There is no good reason to convert a socket to a pointer. You can use socket.fileno() to get the socket's file descriptor which should be usable in C code.
If your library expects a pointer, you might need to wrap it with a ctypes struct - but without knowing details we can't tell. | 1 | 0 | 0 | Is there any way of converting the python socket object to a void pointer. I am using ctypes and I have tried using cast and the conversion functions of python.
I am also using a DLL and there is a function which takes structure as its argument.
But when i pass the structure to the function I am getting invalid parame... | PYTHON Sockets and structure | 1.2 | 0 | 1 | 203 |
5,496,911 | 2011-03-31T08:11:00.000 | 2 | 0 | 1 | 0 | c++,python | 5,496,958 | 2 | false | 0 | 0 | Python dicts are an implementation of the generic data structure commonly referred to as a hash table or hash map.
For Python dicts, complexities are what you would expect from an efficient implementation of a hash table; insert is constant time; iteration is O(N). Dictionaries are unsorted; if you want something that'... | 2 | 0 | 0 | Is dictionary in Python can be seen as Map in C++
And the insert complexity is constant time?
and what about sort complexity of dictionary?
What about iteration?
Need some good points or link to good resource.
Thanks! | Is dictionary in Python can be seen as Map in C++ | 0.197375 | 0 | 0 | 159 |
5,496,911 | 2011-03-31T08:11:00.000 | 2 | 0 | 1 | 0 | c++,python | 5,496,954 | 2 | true | 0 | 0 | If I recall correctly, the C++ map implementation uses a tree, so insertion and retrieval is O(log(n)) as opposed to O(1).
Python uses hashtables, so retrieval is O(1). | 2 | 0 | 0 | Is dictionary in Python can be seen as Map in C++
And the insert complexity is constant time?
and what about sort complexity of dictionary?
What about iteration?
Need some good points or link to good resource.
Thanks! | Is dictionary in Python can be seen as Map in C++ | 1.2 | 0 | 0 | 159 |
5,497,268 | 2011-03-31T08:44:00.000 | 1 | 0 | 0 | 0 | python,screen-scraping,scrapy | 8,621,234 | 6 | false | 1 | 0 | You can use a empty allowed_domains attribute to instruct scrapy not to filter any offsite request. But in that case you must be careful and only return relevant requests from your spider. | 3 | 6 | 0 | I have around 10 odd sites that I wish to scrape from. A couple of them are wordpress blogs and they follow the same html structure, albeit with different classes. The others are either forums or blogs of other formats.
The information I like to scrape is common - the post content, the timestamp, the author, title and ... | what is the best way to scrape multiple domains with scrapy? | 0.033321 | 0 | 1 | 3,829 |
5,497,268 | 2011-03-31T08:44:00.000 | 0 | 0 | 0 | 0 | python,screen-scraping,scrapy | 5,508,257 | 6 | false | 1 | 0 | You should use BeautifulSoup especially if you're using Python. It enables you to find elements in the page, and extract text using regular expressions. | 3 | 6 | 0 | I have around 10 odd sites that I wish to scrape from. A couple of them are wordpress blogs and they follow the same html structure, albeit with different classes. The others are either forums or blogs of other formats.
The information I like to scrape is common - the post content, the timestamp, the author, title and ... | what is the best way to scrape multiple domains with scrapy? | 0 | 0 | 1 | 3,829 |
5,497,268 | 2011-03-31T08:44:00.000 | 1 | 0 | 0 | 0 | python,screen-scraping,scrapy | 6,232,758 | 6 | false | 1 | 0 | I do sort of the same thing using the following XPath expressions:
'/html/head/title/text()' for the title
//p[string-length(text()) > 150]/text() for the post content. | 3 | 6 | 0 | I have around 10 odd sites that I wish to scrape from. A couple of them are wordpress blogs and they follow the same html structure, albeit with different classes. The others are either forums or blogs of other formats.
The information I like to scrape is common - the post content, the timestamp, the author, title and ... | what is the best way to scrape multiple domains with scrapy? | 0.033321 | 0 | 1 | 3,829 |
5,497,540 | 2011-03-31T09:11:00.000 | 1 | 1 | 0 | 0 | php,python | 45,145,842 | 4 | false | 0 | 0 | You can try this:
python scripts:
test.py:
print "hello"
then php Scripts
index.php:
$i =`python test.py`;
echo $i; | 1 | 13 | 0 | I have some code written in PHP, but I have also developed a script written in Python. Is it possible to call this Python script from the PHP code?
If yes, how can I pass parameters to the Python script from the PHP?
I have tried to find an answer without any success.
Can someone give me a clue? | How to call a Python Script from PHP? | 0.049958 | 0 | 0 | 43,993 |
5,498,704 | 2011-03-31T10:54:00.000 | 0 | 0 | 1 | 1 | python,file-management | 5,631,968 | 2 | true | 0 | 0 | It is impossible, OS does not store such info about files. Answered by 'atzz' in comment | 1 | 0 | 0 | lets say that some files were renamed by Python script, is it possible to get this 'rename time' using Python (It can be seen in Far Manager)? (Windows)
It seems it is not possible through STAT, etc
Any ideas ? | python file was renamed, how to get 'rename time' | 1.2 | 0 | 0 | 239 |
5,499,558 | 2011-03-31T12:06:00.000 | 0 | 1 | 0 | 0 | php,python,stdout,stdin,web-crawler | 5,499,681 | 3 | false | 1 | 0 | Since i don't know too much about how python works just treat this like a wild idea.
Create an XML on your server which is accessible by both of python and PHP
On the PHP side you can insert new nodes to this XML about new urls with a processed=false flag
Python come and see for unprocessed tasks then fetch data and p... | 2 | 1 | 0 | I've got a python crawler crawling a few webpages every few minutes. I'm now trying to implement a user interface to be accessed over the web and to display the data obtained by the crawler. I'm going to use php/html for the interface. Anyway, the user interface needs some sort of button which triggers the crawler to c... | Passing Data to a Python Web Crawler from PHP Script | 0 | 0 | 1 | 1,079 |
5,499,558 | 2011-03-31T12:06:00.000 | 1 | 1 | 0 | 0 | php,python,stdout,stdin,web-crawler | 5,500,025 | 3 | false | 1 | 0 | Best possible way to remove dependencies of working with different languages is to use a message queuing library (like rabbitMQ or ActiveMQ)
By using this you can send direct messages from php to python or vice versa...
If you want an easy way out you need to modify your python script(more on the lines of what fabrik s... | 2 | 1 | 0 | I've got a python crawler crawling a few webpages every few minutes. I'm now trying to implement a user interface to be accessed over the web and to display the data obtained by the crawler. I'm going to use php/html for the interface. Anyway, the user interface needs some sort of button which triggers the crawler to c... | Passing Data to a Python Web Crawler from PHP Script | 0.066568 | 0 | 1 | 1,079 |
5,502,787 | 2011-03-31T16:01:00.000 | 2 | 0 | 1 | 0 | c++,python,c,connection,io | 5,502,815 | 3 | true | 0 | 0 | Yes. Open the first file in Python, process it and save the results to a second file.
Then open the second file in your C or C++ program and use the data. | 1 | 3 | 0 | What I am trying to do is that I want to read a file using python, and then with the data in the file, create a variable in c/c++(I don't want to read var from the file :) ).
Is this possible?
If this is possible, then how would you do it?
Thank you guys! | connecting c/c++ and python | 1.2 | 0 | 0 | 5,001 |
5,503,677 | 2011-03-31T17:16:00.000 | 0 | 0 | 1 | 0 | python,command-line,pygtk,graphicsmagick | 5,522,172 | 2 | false | 0 | 0 | You could use an idle function that calls subprocess.Popen() and returns True if there are still pages left to process. That means it will be called again at the next available opportunity. When you are finished with the pages, you can return False from the idle function and it will not be called anymore. | 1 | 1 | 0 | I am in PyGtk on Windows. My program converts PDF's to images using GraphicsMagick then displays the image. The conversion can be very long on multi-page PDF's so the program has to wait for the command line to return and I need to get around this and allow the user to use the GUI while the image is created. My attempt... | Pygtk threading long command line process | 0 | 0 | 0 | 288 |
5,503,820 | 2011-03-31T17:27:00.000 | 1 | 0 | 0 | 1 | python,erlang,machine-learning,classification,correlation | 5,516,971 | 2 | false | 0 | 0 | Your problem is a tactical problem as opposed to a procedural problem. Both types have their own set of tools, and you will be in a world of pain if you try to solve a tactical problem with procedural tools.
Just to clarify terms, when i say procedural, I am talking about use cases where you can say do X, then Y, then... | 1 | 9 | 0 | Got an asynchronous stream of events, where each event has information like -
Agency (one of many Agencies possible to be served by my solution)
Agent (one of many Agents in an Agency)
Served-Entity (a person/organization served by 1 or more agencies)
Date+Time
Class-Data (tags from a fixed but large set of tags)
Wha... | Event correlation and filtering - How to, where-to start? | 0.099668 | 0 | 0 | 1,981 |
5,505,211 | 2011-03-31T19:28:00.000 | 0 | 0 | 1 | 0 | python,types | 5,505,310 | 3 | false | 0 | 0 | Firstly, Python generally does not have maxint value since it's integer type is unbounded. When it goes over sys.maxint it turns into a long type. Still you can easily implement what you want by writing descriptor if you want this to be class attribute and property if you want this to be instance attribute. | 1 | 3 | 0 | Quick one hopefully; brain has gone blank.
Is it possible / practical to have a class that is just a generic numeric value (eg float, int, etc) that when a value becomes <=0 it loops around to os.maxint-value, similar to a unsigned value in C?
'This is completely insane' is also an acceptable answer!
'Reasonable' use ... | Python Custom Numeric Types: Wrap around number | 0 | 0 | 0 | 2,576 |
5,506,110 | 2011-03-31T20:46:00.000 | 20 | 0 | 1 | 0 | python,virtualenv | 5,506,336 | 12 | false | 0 | 0 | Pre-requisites:
sudo easy_install virtualenv
sudo pip install virtualenvwrapper
Installing virtualenv with Python2.6:
You could manually download, build and install another version of Python to /usr/local or another location.
If it's another location other than /usr/local, add it to your PATH.
Reload your shell to... | 2 | 153 | 0 | I have a shared account in a web-hosting that has Python 2.4 installed, but my code is not compatible with 2.4. Is it possible to install Python 2.6 directly to Virtualenv?
Note: I don´t have permission to install it in the shared server. | Is it possible to install another version of Python to Virtualenv? | 1 | 0 | 0 | 130,767 |
5,506,110 | 2011-03-31T20:46:00.000 | 3 | 0 | 1 | 0 | python,virtualenv | 5,506,228 | 12 | false | 0 | 0 | The usual approach is to download the source and build and install locally (but not directly in virtualenv), and then create a new virtualenv using that local Python install. On some systems, it may be possible to download and install a prebuilt python, rather than building from source. | 2 | 153 | 0 | I have a shared account in a web-hosting that has Python 2.4 installed, but my code is not compatible with 2.4. Is it possible to install Python 2.6 directly to Virtualenv?
Note: I don´t have permission to install it in the shared server. | Is it possible to install another version of Python to Virtualenv? | 0.049958 | 0 | 0 | 130,767 |
5,507,531 | 2011-03-31T23:18:00.000 | 7 | 1 | 1 | 0 | python,c,reverse-engineering,cython | 5,507,763 | 3 | true | 0 | 0 | Okay -- to attempt to answer your question more directly: most auto-generated C code is fairly ugly, so somebody would need to be fairly motivated to reverse engineer it. At the same time, I don't believe I've never looked at what Cython generates, so I'm not sure how it looks.
In addition, a lot of auto-generated code... | 3 | 7 | 0 | How easy is it to reverse engineer an auto-generated C code? I am working on a Python project and as part of my work, am using Cython to compile the code for speedup purposes.
This does help in terms of speed, yet, I am concerned that where I work, some people would try to "peek" into the code and figure out what it do... | Reverse Engineer Auto-Generated C? | 1.2 | 0 | 0 | 2,870 |
5,507,531 | 2011-03-31T23:18:00.000 | 2 | 1 | 1 | 0 | python,c,reverse-engineering,cython | 5,687,219 | 3 | false | 0 | 0 | You should really take a look at the code that Cython produces. To help with debugging, for example, it copies the complete Python source code into the generated file, marking each source line before generating C code for it. That makes it very easy to find the code section that you are interested in.
A very nice featu... | 3 | 7 | 0 | How easy is it to reverse engineer an auto-generated C code? I am working on a Python project and as part of my work, am using Cython to compile the code for speedup purposes.
This does help in terms of speed, yet, I am concerned that where I work, some people would try to "peek" into the code and figure out what it do... | Reverse Engineer Auto-Generated C? | 0.132549 | 0 | 0 | 2,870 |
5,507,531 | 2011-03-31T23:18:00.000 | 2 | 1 | 1 | 0 | python,c,reverse-engineering,cython | 5,687,328 | 3 | false | 0 | 0 | Ah, I guess I missed the bit that you were talking about the compiled module, whereas I was only referring to the source code that Cython generates. I agree with Jerry that it will be fairly tricky to extract something useful from the compiled module, as long as you keep the gdb support disabled (the default) and strip... | 3 | 7 | 0 | How easy is it to reverse engineer an auto-generated C code? I am working on a Python project and as part of my work, am using Cython to compile the code for speedup purposes.
This does help in terms of speed, yet, I am concerned that where I work, some people would try to "peek" into the code and figure out what it do... | Reverse Engineer Auto-Generated C? | 0.132549 | 0 | 0 | 2,870 |
5,508,113 | 2011-04-01T00:50:00.000 | 0 | 0 | 1 | 0 | python,installation,pythonxy | 5,508,380 | 1 | false | 1 | 0 | there is a simple way, delete the pythonxy directory (same as c:\python2.6),
then run pythonxy.exe again. | 1 | 0 | 0 | For convenience, I am applying pythonxy
But when I try to reload or uninstall,log2del has been in the process,program stoped there
I can not reinstall or uninsall | pythonxy can't be reinstalled or uninsalled | 0 | 0 | 0 | 927 |
5,508,314 | 2011-04-01T01:30:00.000 | 1 | 0 | 1 | 0 | python,html | 5,508,324 | 2 | false | 1 | 0 | look in the direction of beautiful soup. | 1 | 0 | 0 | How can I get plain text (stripped of HTML) from inside a any tag with the class name of calendardescription given a URL in python? Matching text in different tags should also be separated by a blank line. This is for text to speech purposes.
Thanks in advance. | How can I get plain text from within a HTML class given a URL in python? | 0.099668 | 0 | 1 | 197 |
5,508,509 | 2011-04-01T02:16:00.000 | 2 | 0 | 1 | 0 | python,json | 5,508,597 | 5 | false | 0 | 0 | I would say parsing it is the only way you can really entirely tell. Exception will be raised by python's json.loads() function (almost certainly) if not the correct format. However, the the purposes of your example you can probably just check the first couple of non-whitespace characters...
I'm not familiar with the J... | 1 | 246 | 0 | In Python, is there a way to check if a string is valid JSON before trying to parse it?
For example working with things like the Facebook Graph API, sometimes it returns JSON, sometimes it could return an image file. | How do I check if a string is valid JSON in Python? | 0.07983 | 0 | 1 | 268,500 |
5,509,803 | 2011-04-01T06:17:00.000 | 0 | 0 | 1 | 0 | python,string | 5,509,848 | 2 | false | 0 | 0 | I don't really understand your question, but I'll try to give you some solutions.
If you gonna print pure '\x41', you could just
print r'\x41'
And if what you want is to print the 'A' out, pls do:
print u'\x41' | 1 | 0 | 0 | How can I convert a string like '\\x41' to an escaped string like '\x41', using Python? | Python: '\\x41' to '\x41' | 0 | 0 | 0 | 743 |
5,509,872 | 2011-04-01T06:26:00.000 | 0 | 0 | 1 | 1 | python,file,append | 57,903,899 | 12 | false | 0 | 0 | There's also the fileinput class in Python 3, which is perfect for this sort of situation | 1 | 21 | 0 | I have up to 8 seperate Python processes creating temp files in a shared folder. Then I'd like the controlling process to append all the temp files in a certain order into one big file. What's the quickest way of doing this at an os agnostic shell level? | Python append multiple files in given order to one big file | 0 | 0 | 0 | 67,484 |
5,513,712 | 2011-04-01T12:59:00.000 | 1 | 0 | 0 | 0 | python,save,yaml | 5,513,797 | 2 | true | 0 | 0 | YAML is a way of serialising and deserialising dictionaries and lists between Python and a text-editable format. It isn't suited for storing rich data, multi-user access, fast lookups of data, guaranteeing data integrity and all the other things that make a database a database.
You're using YAML as a database, but it'... | 1 | 1 | 0 | I've discovered YAML recently and it has turned out to be a fantastic format for my project (I'm creating a text-based RPG). It's handling everything I need flawlessly - area files (rooms with descs, exits, objs, npcs, etc), script files, npc files, object files... it tackles them all! There's just one thing...
When up... | I don't like how "yaml.dump()" saves its files. Is there an alternative? | 1.2 | 0 | 0 | 1,129 |
5,514,330 | 2011-04-01T13:51:00.000 | 2 | 0 | 1 | 0 | python | 5,514,359 | 4 | false | 0 | 0 | Google for python decorator and you will find enough answers to your question. | 1 | 1 | 0 | Just a quick question,
Could someone link me to the documentation for the use of @ in python?
Due not being able to google @ and not knowing the use or name of it I'm not sure how to find it on my own :)
Many thanks!! | Python documentation for @? | 0.099668 | 0 | 0 | 366 |
5,515,051 | 2011-04-01T14:53:00.000 | 9 | 0 | 1 | 0 | python | 5,515,074 | 1 | true | 0 | 0 | Yes. If you started Python without -O you'll need the .pyc file, and with -O you will need .pyo. | 1 | 2 | 0 | Well,
Is it possible to import "os" module with "os.pyo" or "os.pyc" instead of "os.py"?
Thank you | Is it possible to import .pyo files | 1.2 | 0 | 0 | 2,803 |
5,515,157 | 2011-04-01T15:01:00.000 | 0 | 0 | 0 | 0 | java,python,web-services,web-applications | 5,515,258 | 4 | false | 1 | 0 | When developing in a framework, it is generally simpler to develop with the language of the framework than it is to develop with a different language.
Servlets are components of the web server (which is also called a Servlet container). The Servlet container and the required Servlet API is all Java. While you could F... | 1 | 0 | 0 | Forgive me if this is a stupid question. I am completely new to building web services and complete web apps.
I want to develop a particular functionality for a java based web application. However this functionality is simpler to develop with Python. So is it possible If i develop this web service with Python and use i... | Python web service for a java application? | 0 | 0 | 0 | 2,930 |
5,517,582 | 2011-04-01T18:51:00.000 | 25 | 0 | 1 | 0 | python | 5,518,062 | 7 | false | 0 | 0 | This point hasn't been made yet, and should be:
You are not going to be able to secure arbitrary Python code.
A VM is the way to go unless you want security issues up the wazoo. | 3 | 25 | 0 | I am about to get a bunch of python scripts from an untrusted source.
I'd like to be sure that no part of the code can hurt my system, meaning:
(1) the code is not allowed to import ANY MODULE
(2) the code is not allowed to read or write any data, connect to the network etc
(the purpose of each script is to loop throug... | Dangerous Python Keywords? | 1 | 0 | 0 | 3,278 |
5,517,582 | 2011-04-01T18:51:00.000 | 2 | 0 | 1 | 0 | python | 9,952,357 | 7 | false | 0 | 0 | built in functions/keywords:
eval
exec
__import__
open
file
input
execfile
print can be dangerous if you have one of those dumb shells that execute code on seeing certain output
stdin
__builtins__
globals() and locals() must be blocked otherwise they can be used to bypass your rules
There's probably tons of others th... | 3 | 25 | 0 | I am about to get a bunch of python scripts from an untrusted source.
I'd like to be sure that no part of the code can hurt my system, meaning:
(1) the code is not allowed to import ANY MODULE
(2) the code is not allowed to read or write any data, connect to the network etc
(the purpose of each script is to loop throug... | Dangerous Python Keywords? | 0.057081 | 0 | 0 | 3,278 |
5,517,582 | 2011-04-01T18:51:00.000 | 1 | 0 | 1 | 0 | python | 5,520,646 | 7 | false | 0 | 0 | Use a Virtual Machine instead of running it on a system that you are concerned about. | 3 | 25 | 0 | I am about to get a bunch of python scripts from an untrusted source.
I'd like to be sure that no part of the code can hurt my system, meaning:
(1) the code is not allowed to import ANY MODULE
(2) the code is not allowed to read or write any data, connect to the network etc
(the purpose of each script is to loop throug... | Dangerous Python Keywords? | 0.028564 | 0 | 0 | 3,278 |
5,519,714 | 2011-04-01T22:54:00.000 | 7 | 0 | 0 | 0 | python,uno,odt | 5,520,909 | 2 | true | 1 | 0 | Your mileage with odfpy may vary. I didn't like it - I ended up using a template ODT, created in OpenOffice, oppening the contents.xml with ziplib and elementtree, and updating that. (In your case, it would create only the relevant table rows and table cell nodes), then recorded everything back.
It is actually straight... | 1 | 6 | 0 | My point is that using either pod (from appy framework, which is a pain to use for me) or the OpenOffice UNO bridge that seems soon to be deprecated, and that requires OOo.org to run while launching my script is not satisfactory at all.
Can anyone point me to a neat way to produce a simple yet clean ODT (tables are my ... | Is there a simple way to write an ODT using Python? | 1.2 | 0 | 0 | 4,956 |
5,520,180 | 2011-04-02T00:20:00.000 | 0 | 0 | 1 | 0 | python,string,indexing | 5,520,211 | 3 | false | 0 | 0 | index() is the same thing as find() except for the error when the string isn't found. | 1 | 1 | 0 | How can I write a function that returns the index of a single character in a string without using the index method a.k.a string.index('some random character')? | Python: How to get the Index of a string | 0 | 0 | 0 | 5,945 |
5,520,594 | 2011-04-02T01:55:00.000 | 0 | 0 | 1 | 0 | python,xml,json | 5,556,531 | 3 | false | 0 | 0 | My current solution to this problem is to require the JSON to be in the most compact format. No whitespace, ;:, etc.
Reformatting it should be OK, so long as we always reformat to the same thing. | 3 | 3 | 0 | I am receiving several objects, currently in JSON, and need to be able to modify parts of them, while leaving the later parts EXACTLY, space for space, bit for bit, identical.
For instance, Imagine I was receiving following object
{
"example": [
{
"Name": "Thing One",
"Line2... | How can I edit a JSON element in-place, without rewriting the rest of the JSON object? | 0 | 0 | 0 | 889 |
5,520,594 | 2011-04-02T01:55:00.000 | 1 | 0 | 1 | 0 | python,xml,json | 5,520,812 | 3 | false | 0 | 0 | The best answer to this question may be "Don't Do that."
If I need the bits to remain identical, I can replace "Thing Three" with a BASE64 or yENC encoded version of itself. | 3 | 3 | 0 | I am receiving several objects, currently in JSON, and need to be able to modify parts of them, while leaving the later parts EXACTLY, space for space, bit for bit, identical.
For instance, Imagine I was receiving following object
{
"example": [
{
"Name": "Thing One",
"Line2... | How can I edit a JSON element in-place, without rewriting the rest of the JSON object? | 0.066568 | 0 | 0 | 889 |
5,520,594 | 2011-04-02T01:55:00.000 | 2 | 0 | 1 | 0 | python,xml,json | 5,520,644 | 3 | true | 0 | 0 | The object_pairs_hook argument of the json load functions will allow you to use a OrderedDictionary such that you can retain the same order of the elements of JSON objects. | 3 | 3 | 0 | I am receiving several objects, currently in JSON, and need to be able to modify parts of them, while leaving the later parts EXACTLY, space for space, bit for bit, identical.
For instance, Imagine I was receiving following object
{
"example": [
{
"Name": "Thing One",
"Line2... | How can I edit a JSON element in-place, without rewriting the rest of the JSON object? | 1.2 | 0 | 0 | 889 |
5,520,655 | 2011-04-02T02:10:00.000 | 1 | 1 | 0 | 0 | python,bit-manipulation | 5,520,784 | 9 | false | 0 | 0 | It's a little silly to try and aggressively optimize Python code, so a simple for loop with counter and right-shift should be fine. If you wanted to go faster (which would make more sense in C, Java, or Assembly) you could binary-search for the right-most 1-bit and even use lookup tables to help you.
Suppose x is 64-b... | 1 | 16 | 0 | C++ has a set of functions, ffs(), ffsl(), and ffsll(), that return the least significant bit that is set in a given binary integer.
I'm wondering if there is an equivalent function already available in Python. I don't see one described for bitarray, but perhaps there's another. I am hoping to avoid calculating the ans... | return index of least significant bit in Python | 0.022219 | 0 | 0 | 14,720 |
5,521,165 | 2011-04-02T04:29:00.000 | 1 | 0 | 1 | 0 | java,python,programming-languages,rrdtool,rrd | 5,521,343 | 3 | true | 0 | 0 | You could try using JPython to bridge it to Java.
But the easiest is probably to either use Python, or fix the bygs in JRobin. It's open source after all. | 2 | 0 | 0 | How can you properly read RRD files using Java? We are using tools like JRobin, etc. but my team is having problems with those tools, they don't seem to properly read the RRD files. We need to use RRDTool, and that tool is an importable library for Python. | How can you properly read RRD files using Java? | 1.2 | 0 | 0 | 2,790 |
5,521,165 | 2011-04-02T04:29:00.000 | 1 | 0 | 1 | 0 | java,python,programming-languages,rrdtool,rrd | 5,525,492 | 3 | false | 0 | 0 | use the "rrdtool -" pipe interface and use the real rrdtool to access the files. | 2 | 0 | 0 | How can you properly read RRD files using Java? We are using tools like JRobin, etc. but my team is having problems with those tools, they don't seem to properly read the RRD files. We need to use RRDTool, and that tool is an importable library for Python. | How can you properly read RRD files using Java? | 0.066568 | 0 | 0 | 2,790 |
5,521,463 | 2011-04-02T05:54:00.000 | 2 | 0 | 1 | 0 | oop,python | 5,521,921 | 3 | true | 0 | 0 | You can use __new__, but a factory function is the nice pythonic way to go. | 1 | 1 | 0 | What is the best way to vary what class is instantiated based off parameters to an initialization function in Python? For example, for a quadtree, if the number of elements is below a certain threshold, you want to return a leaf rather than a branch. Another example would be a graph which can either be backed by a adja... | Altering which class is instantiated based off initialization parameters | 1.2 | 0 | 0 | 133 |
5,522,334 | 2011-04-02T09:23:00.000 | 0 | 1 | 1 | 0 | python,unit-testing,doctest | 5,523,349 | 4 | false | 0 | 0 | Some tests will need things like databases set up and initialised.
This could make doctests:
very verbose (and therefore not good
documentation); and
probably inefficient because in doctests you would typically set
up the database for each function or class. In comparison,
unit tests more easily could use the
same ... | 4 | 0 | 0 | The question is quite clear, ... note however that I am NOT asking about a feature comparison (there are a lot of them already), nor am I asking about which one you prefer !
I have myself a clear preference for doctests, I use them for everything, even if those are not to be used for documentation. But what I am wonder... | Python: Does 'unittest' have something that 'doctest' hasn't? | 0 | 0 | 0 | 370 |
5,522,334 | 2011-04-02T09:23:00.000 | 0 | 1 | 1 | 0 | python,unit-testing,doctest | 5,522,673 | 4 | false | 0 | 0 | Doctests are limited to per function (or per class) tests. You cannot do things like taking the output of one function and trying it with another etc. It's best used for "example" type tests (i.e. how do I use this function?)
Unit tests can be larger and more involved than doctests. | 4 | 0 | 0 | The question is quite clear, ... note however that I am NOT asking about a feature comparison (there are a lot of them already), nor am I asking about which one you prefer !
I have myself a clear preference for doctests, I use them for everything, even if those are not to be used for documentation. But what I am wonder... | Python: Does 'unittest' have something that 'doctest' hasn't? | 0 | 0 | 0 | 370 |
5,522,334 | 2011-04-02T09:23:00.000 | 6 | 1 | 1 | 0 | python,unit-testing,doctest | 5,522,962 | 4 | false | 0 | 0 | There is a widespread misconception that doctest is for testing your code. doctest is intended for testing your documentation. doctest is intended to test that your documentation matches what the function/class/module is actually doing, and alerts you if sample code in your documentation becomes obsolete as the module ... | 4 | 0 | 0 | The question is quite clear, ... note however that I am NOT asking about a feature comparison (there are a lot of them already), nor am I asking about which one you prefer !
I have myself a clear preference for doctests, I use them for everything, even if those are not to be used for documentation. But what I am wonder... | Python: Does 'unittest' have something that 'doctest' hasn't? | 1 | 0 | 0 | 370 |
5,522,334 | 2011-04-02T09:23:00.000 | 3 | 1 | 1 | 0 | python,unit-testing,doctest | 5,523,855 | 4 | true | 0 | 0 | There are some test scenarios doctests simply don't cover very well. That's OK since, as Lie pointed out, doctests aren't meant to be a comprehensive testing solution - they're meant to ensure that simple interactive-prompt style examples in your documentation (including docstrings) don't get out of date.
Writing actua... | 4 | 0 | 0 | The question is quite clear, ... note however that I am NOT asking about a feature comparison (there are a lot of them already), nor am I asking about which one you prefer !
I have myself a clear preference for doctests, I use them for everything, even if those are not to be used for documentation. But what I am wonder... | Python: Does 'unittest' have something that 'doctest' hasn't? | 1.2 | 0 | 0 | 370 |
5,522,809 | 2011-04-02T11:18:00.000 | 0 | 0 | 0 | 0 | python,web,client-side,server-side | 5,522,817 | 5 | false | 0 | 0 | Of course it is. But without more information on what type of game it is impossible to provide further guidance. | 2 | 1 | 0 | I was wondering if it is possible to implement a web based game in python. I have searched the internet and cannot seem to find any tutorial or document pointing to this. Any advice will be appreciated.. | python web based game | 0 | 0 | 1 | 10,562 |
5,522,809 | 2011-04-02T11:18:00.000 | 0 | 0 | 0 | 0 | python,web,client-side,server-side | 5,558,715 | 5 | false | 0 | 0 | Python can be used in a variety of ways for developing web games. In particular, it can be very useful for doing the back-end of a multiplayer game. For the front-end you will probably need to use a client-side technology like Flash, but there have been turn-based games that simply use static HTML as the front-end (for... | 2 | 1 | 0 | I was wondering if it is possible to implement a web based game in python. I have searched the internet and cannot seem to find any tutorial or document pointing to this. Any advice will be appreciated.. | python web based game | 0 | 0 | 1 | 10,562 |
5,523,546 | 2011-04-02T13:51:00.000 | 2 | 1 | 1 | 0 | python,pylons,pyramid | 8,312,263 | 6 | false | 0 | 0 | It seems to me, that the solutions above do not exactly copy the behavior of Pylons template context. If one renders a page request in Pylons and adds some value a to the context c, it is accessible in the template as c.a. However, if one renders another request, this key/value will be dropped.
The Pyramid solutions ab... | 1 | 14 | 0 | What is the equivalent of template context in Pyramid?
Does the IBeforeRender event in pyramid have anything to with this? I've gone through the official documentation but diffcult to understand what the IBeforeRender event is exactly. | Equivalent of template context in Pyramid (pylons user) | 0.066568 | 0 | 0 | 2,766 |
5,523,747 | 2011-04-02T14:33:00.000 | 2 | 0 | 1 | 0 | javascript,python,namespaces,interactive,dir | 5,524,753 | 9 | false | 1 | 0 | The global variables are kept in an easily accessible object (window) and so you can inspect/iterate over them easily. (Using something like the functions suggested by Glenjamin)
On the other hand, I don't know of any way to inspect local variables defined in functions or closures - if this is possible I'd at least gue... | 1 | 58 | 0 | when I write Python code from the interpreter I can type dir() to have a list of names defined in the current scope. How can achieve to have the same information, programmatically, when I develop Javascript code from a browser using an interactive console like firebug, chrome console, etc? | Equivalent of Python's dir in Javascript | 0.044415 | 0 | 0 | 18,362 |
5,524,780 | 2011-04-02T17:41:00.000 | 5 | 0 | 0 | 1 | c++,python,linux,multithreading,event-driven | 5,525,008 | 8 | false | 0 | 0 | I've solved this exact problem using what you mention, pipe() and libevent (which wraps epoll). The worker thread writes a byte to its pipe FD when its output queue goes from empty to non-empty. That wakes up the main IO thread, which can then grab the worker thread's output. This works great is actually very simple... | 3 | 21 | 0 | I would like to spawn off threads to perform certain tasks, and use a thread-safe queue to communicate with them. I would also like to be doing IO to a variety of file descriptors while I'm waiting.
What's the recommended way to accomplish this? Do I have to created an inter-thread pipe and write to it when the queue g... | I want to wait on both a file descriptor and a mutex, what's the recommended way to do this? | 0.124353 | 0 | 0 | 10,042 |
5,524,780 | 2011-04-02T17:41:00.000 | 3 | 0 | 0 | 1 | c++,python,linux,multithreading,event-driven | 36,855,042 | 8 | false | 0 | 0 | It seems nobody has mentioned this option yet:
Don't run select/poll/etc. in your "main thread". Start a dedicated secondary thread which does the I/O and pushes notifications into your thread-safe queue (the same queue which your other threads use to communicate with the main thread) when I/O operations complete.
Then... | 3 | 21 | 0 | I would like to spawn off threads to perform certain tasks, and use a thread-safe queue to communicate with them. I would also like to be doing IO to a variety of file descriptors while I'm waiting.
What's the recommended way to accomplish this? Do I have to created an inter-thread pipe and write to it when the queue g... | I want to wait on both a file descriptor and a mutex, what's the recommended way to do this? | 0.07486 | 0 | 0 | 10,042 |
5,524,780 | 2011-04-02T17:41:00.000 | 1 | 0 | 0 | 1 | c++,python,linux,multithreading,event-driven | 5,524,930 | 8 | false | 0 | 0 | C++11 has std::mutex and std::condition_variable. The two can be used to have one thread signal another when a certain condition is met. It sounds to me like you will need to build your solution out of these primitives. If you environment does not yet support these C++11 library features, you can find very similar o... | 3 | 21 | 0 | I would like to spawn off threads to perform certain tasks, and use a thread-safe queue to communicate with them. I would also like to be doing IO to a variety of file descriptors while I'm waiting.
What's the recommended way to accomplish this? Do I have to created an inter-thread pipe and write to it when the queue g... | I want to wait on both a file descriptor and a mutex, what's the recommended way to do this? | 0.024995 | 0 | 0 | 10,042 |
5,524,991 | 2011-04-02T18:17:00.000 | 1 | 0 | 0 | 1 | python,html,xml,google-app-engine,datastore | 5,525,121 | 1 | true | 1 | 0 | Use a StringIO when you need a file-like object for use with libraries that act on files. (Although I believe most XML parsers will happily accept a string instead of requiring a file-like object.) | 1 | 1 | 0 | I want to provide a field in my html file so that people can upload their XML files to be imported to the datastore. How can I read and process this file inside the app engine once it is uploaded ? (I dont want to store the file with blobstore. Just want to read, process and throw it away) Thanks | file I/O with google app engine | 1.2 | 0 | 0 | 278 |
5,525,544 | 2011-04-02T20:04:00.000 | 1 | 0 | 1 | 1 | python,windows,python-3.x,python-2.7 | 5,525,559 | 5 | false | 0 | 0 | You can read the variable __file__ to find out the path to the current Python file being interpreted. | 1 | 1 | 0 | (Python2.7-3.2 on WindowsXP)
I used to use sys.arg[0], but now I'm executing it from a batch script(for determining if the user has python)
Thanks ^^
~ps: Suggest if you know a better way to find out if the user has Python | Is there a way to tell where your python file is? | 0.039979 | 0 | 0 | 226 |
5,526,666 | 2011-04-02T23:53:00.000 | 4 | 0 | 1 | 0 | python,version | 5,526,688 | 3 | false | 0 | 0 | The 2.x versions are (generally - if 2.x had a bug somewhere and some fool writes code that takes this incorrect behaviour for granted, upgrade to 2.(x+1) will of course change the behaviour) backwards-compatible. So the examples written for 2.5 should run fine for 2.7.
Note though that you're missing out several cool ... | 3 | 3 | 0 | I got a book for python 2.5 but up until now I've been using 2.7. Will there be any huge barriers to overcome? | Python version differences | 0.26052 | 0 | 0 | 2,394 |
5,526,666 | 2011-04-02T23:53:00.000 | 5 | 0 | 1 | 0 | python,version | 5,526,679 | 3 | true | 0 | 0 | No, Python 2.7 is compatible with 2.5. There were a few features that were added, but everything you learned from 2.5 should work in 2.7.
Python 3, on the other hand, makes some big changes that are not compatible with 2.5. | 3 | 3 | 0 | I got a book for python 2.5 but up until now I've been using 2.7. Will there be any huge barriers to overcome? | Python version differences | 1.2 | 0 | 0 | 2,394 |
5,526,666 | 2011-04-02T23:53:00.000 | 0 | 0 | 1 | 0 | python,version | 5,526,683 | 3 | false | 0 | 0 | No, the big differences came from python 2.x to python 3 | 3 | 3 | 0 | I got a book for python 2.5 but up until now I've been using 2.7. Will there be any huge barriers to overcome? | Python version differences | 0 | 0 | 0 | 2,394 |
5,526,783 | 2011-04-03T00:32:00.000 | 0 | 0 | 1 | 0 | python,operating-system,cpu-architecture | 5,527,495 | 5 | false | 0 | 0 | New operating systems are interesting and cool, and basing one off of python would be cool. Then again, linux is so good and has so much development for it already. It would have to be the "right time". | 2 | 3 | 0 | Wouldn't it be possible to have an OS entirely in Python if the Python VM itself is build into a hardware? Something like the good old Lisp Machine?
Suppose I have a cpu that is the hardware implementation of the python virtual machine, then all programs written in python would perform with the speed of assembly, won't... | Python CPU and OS | 0 | 0 | 0 | 2,032 |
5,526,783 | 2011-04-03T00:32:00.000 | 4 | 0 | 1 | 0 | python,operating-system,cpu-architecture | 5,526,811 | 5 | true | 0 | 0 | Wouldn't it be possible to have an OS
entirely in Python if the Python VM
itself is build into a hardware?
Something like the good old Lisp
Machine?
Yes, theoretically it would be possible.
Suppose I have a cpu that is the
hardware implementation of the python
virtual machine, then all programs
written ... | 2 | 3 | 0 | Wouldn't it be possible to have an OS entirely in Python if the Python VM itself is build into a hardware? Something like the good old Lisp Machine?
Suppose I have a cpu that is the hardware implementation of the python virtual machine, then all programs written in python would perform with the speed of assembly, won't... | Python CPU and OS | 1.2 | 0 | 0 | 2,032 |
5,526,820 | 2011-04-03T00:47:00.000 | 1 | 0 | 0 | 0 | python,django | 5,526,953 | 1 | false | 1 | 0 | There is no out of the box support for this (assuming you're talking replacing the exact, live editing that preopulated_fields provides).
The slug function is written in JavaScript, in django/contrib/admin/media/js/urlify.js
You could potentially insert a new script in the ModelAdmin extra JS property, but make sure yo... | 1 | 0 | 0 | In the Django admin, I can set a slug field to fill in automatically using prepopulated_fields. How can I set a field to fill in using a different function, for example just basic concatenation instead of lowercase and spaces-to-hyphens ? | Prepopulate initial values for fields in the Django Admin without slugifying | 0.197375 | 0 | 0 | 363 |
5,526,981 | 2011-04-03T01:29:00.000 | 2 | 0 | 1 | 0 | python,pickle | 5,527,011 | 2 | true | 0 | 0 | You can pickle plain functions. Python stores the name and module and uses that to reload it. If you want to do the same with methods and such that's a little bit trickier. It can be done by breaking such objects down into component parts and pickling those. | 2 | 1 | 1 | I've got a long-running script, and the operations that it performs can be broken down into independent, but order-sensitive function calls. In addition, the pattern here is a bread-first walk over a graph, and restarting a depth after a crash is not a happy option.
So then, my idea is as follows: as the script runs, ... | Can you pickle methods python method objects using any pickle module? | 1.2 | 0 | 0 | 852 |
5,526,981 | 2011-04-03T01:29:00.000 | 0 | 0 | 1 | 0 | python,pickle | 5,526,985 | 2 | false | 0 | 0 | If the arguments are all that matters, why not store the arguments? Just store it as a straight tuple. | 2 | 1 | 1 | I've got a long-running script, and the operations that it performs can be broken down into independent, but order-sensitive function calls. In addition, the pattern here is a bread-first walk over a graph, and restarting a depth after a crash is not a happy option.
So then, my idea is as follows: as the script runs, ... | Can you pickle methods python method objects using any pickle module? | 0 | 0 | 0 | 852 |
5,529,075 | 2011-04-03T10:38:00.000 | 3 | 0 | 1 | 0 | python,large-data,database | 5,529,194 | 3 | false | 0 | 0 | Go with a NoSQL database like MongoDB which is much easier to handle data in such a case than having to learn SQL. | 1 | 4 | 0 | I'm working on an academic project aimed at studying people behavior.
The project will be divided in three parts:
A program to read the data from some remote sources, and build a local data pool with it.
A program to validate this data pool, and to keep it coherent
A web interface to allow people to read/manipulate ... | Handle large data pools in python | 0.197375 | 0 | 0 | 1,451 |
5,529,625 | 2011-04-03T12:39:00.000 | 17 | 0 | 0 | 0 | python,machine-learning,cluster-analysis,k-means,scikit-learn | 9,875,395 | 8 | false | 0 | 0 | Yes you can use a difference metric function; however, by definition, the k-means clustering algorithm relies on the eucldiean distance from the mean of each cluster.
You could use a different metric, so even though you are still calculating the mean you could use something like the mahalnobis distance. | 3 | 213 | 1 | Is it possible to specify your own distance function using scikit-learn K-Means Clustering? | Is it possible to specify your own distance function using scikit-learn K-Means Clustering? | 1 | 0 | 0 | 105,962 |
5,529,625 | 2011-04-03T12:39:00.000 | 57 | 0 | 0 | 0 | python,machine-learning,cluster-analysis,k-means,scikit-learn | 5,531,148 | 8 | false | 0 | 0 | Unfortunately no: scikit-learn current implementation of k-means only uses Euclidean distances.
It is not trivial to extend k-means to other distances and denis' answer above is not the correct way to implement k-means for other metrics. | 3 | 213 | 1 | Is it possible to specify your own distance function using scikit-learn K-Means Clustering? | Is it possible to specify your own distance function using scikit-learn K-Means Clustering? | 1 | 0 | 0 | 105,962 |
5,529,625 | 2011-04-03T12:39:00.000 | 4 | 0 | 0 | 0 | python,machine-learning,cluster-analysis,k-means,scikit-learn | 56,324,541 | 8 | false | 0 | 0 | Sklearn Kmeans uses the Euclidean distance. It has no metric parameter. This said, if you're clustering time series, you can use the tslearn python package, when you can specify a metric (dtw, softdtw, euclidean). | 3 | 213 | 1 | Is it possible to specify your own distance function using scikit-learn K-Means Clustering? | Is it possible to specify your own distance function using scikit-learn K-Means Clustering? | 0.099668 | 0 | 0 | 105,962 |
5,530,708 | 2011-04-03T16:02:00.000 | 14 | 1 | 1 | 0 | python,unicode,console | 5,531,730 | 4 | false | 0 | 0 | Set the environment variable PYTHONIOENCODING to the encoding you want before redirecting a python script to a file. Then you won't have to modify the original script. Make sure to write Unicode strings as well, otherwise PYTHONIOENCODING will have no effect. If you write byte strings, the bytes are sent as-is to th... | 1 | 30 | 0 | I've got a python script that outputs unicode to the console, and I'd like to redirect it to a file. Apparently, the redirect process in python involves converting the output to a string, so I get errors about inability to decode unicode characters.
So then, is there any way to perform a redirect into a file encoded i... | Can I redirect unicode output from the console directly into a file? | 1 | 0 | 0 | 7,460 |
5,531,699 | 2011-04-03T18:52:00.000 | 0 | 0 | 1 | 0 | python,multithreading | 5,531,740 | 3 | false | 0 | 0 | Suppose that you have 50 threads. As long as a single thread is able to write data, then any other thread that reads data can create a problem.
For instance, a thread writes data and then another reads that data. If there is a concurrency problem, it would either read data before or after the change. You wouldn't be ab... | 2 | 0 | 0 | I currently program a program which uses multiple threads. To be able to share data across these threads I use Locks like threading.Lock to avoid access problem during run.
But the problem that I got is that I have to create huge amount locks for every data just for reading that data. Even if I 'group' data and use for... | Possible error reading data from different threads | 0 | 0 | 0 | 87 |
5,531,699 | 2011-04-03T18:52:00.000 | 0 | 0 | 1 | 0 | python,multithreading | 5,532,235 | 3 | false | 0 | 0 | I believe you only have to lock if you write that means that if you have 20 threads reading a only one writing then you only have to lock when the writing one is working reducing 21 locking threads to only one | 2 | 0 | 0 | I currently program a program which uses multiple threads. To be able to share data across these threads I use Locks like threading.Lock to avoid access problem during run.
But the problem that I got is that I have to create huge amount locks for every data just for reading that data. Even if I 'group' data and use for... | Possible error reading data from different threads | 0 | 0 | 0 | 87 |
5,532,541 | 2011-04-03T21:09:00.000 | 0 | 0 | 0 | 0 | javascript,asp.net,python,screen-scraping | 5,532,871 | 3 | false | 1 | 0 | If you are just trying to simulate load, you might want to check out something like selenium, which runs through a browser and handles postbacks like a browser does. | 3 | 1 | 0 | Using Python, I built a scraper for an ASP.NET site (specifically a Jenzabar course searching portlet) that would create a new session, load the first search page, then simulate a search by posting back the required fields. However, something changed, and I can't figure out what, and now I get HTTP 500 responses to eve... | How can I scrape an ASP.NET site that does all interaction as postbacks? | 0 | 0 | 1 | 2,041 |
5,532,541 | 2011-04-03T21:09:00.000 | 2 | 0 | 0 | 0 | javascript,asp.net,python,screen-scraping | 5,532,579 | 3 | true | 1 | 0 | Without knowing any specifics, my hunch is that you are using a hardcoded session id and the web server's app domain recycled and created new encryption/decryption keys, rendering your hardcoded session id (which was encrypted by the old keys) useless. | 3 | 1 | 0 | Using Python, I built a scraper for an ASP.NET site (specifically a Jenzabar course searching portlet) that would create a new session, load the first search page, then simulate a search by posting back the required fields. However, something changed, and I can't figure out what, and now I get HTTP 500 responses to eve... | How can I scrape an ASP.NET site that does all interaction as postbacks? | 1.2 | 0 | 1 | 2,041 |
5,532,541 | 2011-04-03T21:09:00.000 | 0 | 0 | 0 | 0 | javascript,asp.net,python,screen-scraping | 5,532,627 | 3 | false | 1 | 0 | You could try using Firebugs NET tab to monitor all requests, browse around manually and then diff the requests that you generate with ones that your screen scraper is generating. | 3 | 1 | 0 | Using Python, I built a scraper for an ASP.NET site (specifically a Jenzabar course searching portlet) that would create a new session, load the first search page, then simulate a search by posting back the required fields. However, something changed, and I can't figure out what, and now I get HTTP 500 responses to eve... | How can I scrape an ASP.NET site that does all interaction as postbacks? | 0 | 0 | 1 | 2,041 |
5,533,154 | 2011-04-03T23:11:00.000 | 0 | 0 | 1 | 0 | python | 5,533,212 | 3 | false | 0 | 0 | The advantage of (2) is that it uses a generator to produce the key-value tuples, so you avoid the overhead of the N method calls to lambda x() incurred by (1). | 1 | 0 | 0 | with the following dictionary and array:
a = { 'a':[1,2,3,4,5], 'b':[1,2,3], 'c':[1,2,3,4,5] }
b = ['a','c']
I would like to filter a into a new dictionary to only have the key-values in the array b so i end up with:
c = {'a': [1, 2, 3, 4, 5], 'c': [1, 2, 3, 4, 5]}
So.. the obvious way to do this for me was the fol... | question about filtering a dictionary using a list in python | 0 | 0 | 0 | 621 |
5,533,662 | 2011-04-04T01:07:00.000 | 5 | 0 | 1 | 0 | python,abstract-syntax-tree,visitor-pattern | 5,535,381 | 2 | true | 0 | 0 | Nope. You should write your own visitor. Recursively visiting all nodes is fairly simple, so if the ast module stuff doesn't do it for you (and there is nothing in the module to do what you want, in this case), it isn't that bad to do it yourself. | 1 | 3 | 0 | NodeVisitor traverses the AST depth-first and visits each node only once, on enter. Therefore it's problematic to do something serious with it. Is it possible to change its default behavior? | Is it possible to visit nodes in Python AST with ast.NodeVisitor twice or change order of traversal? | 1.2 | 0 | 0 | 2,985 |
5,533,704 | 2011-04-04T01:18:00.000 | 3 | 1 | 1 | 1 | python | 5,533,719 | 2 | false | 0 | 0 | Python itself doesn't impose any limitations on the length or content of sys.argv. However, your operating system and/or command shell definitely will. This question cannot be completely answered without detailed consideration of your operating environment. | 1 | 13 | 0 | Suppose I'd like to run a python script like this: python my_script.py MY_INPUT.
In this case, MY_INPUT will be transmitted to sys.argv[1].
Is there a limit to the number of characters MY_INPUT can contain?
Is there a limit to the type of characters MY_INPUT can contain?
Any other limitations with regards to MY_INPUT... | python sys.argv limitations? | 0.291313 | 0 | 0 | 11,527 |
5,535,206 | 2011-04-04T06:25:00.000 | -1 | 0 | 1 | 0 | python,division,integer-division | 5,535,261 | 5 | false | 0 | 0 | In Python, / operator is for integer division. You can look at it as float division followed by a floor operation.
For example,
8/7 == floor(8.0/7.0) == 1
8/-7 == floor(8.0/-7.0) == -2 | 2 | 58 | 0 | In my application I encountered the following and was surprised by the results:
8/-7=-2 (both integers).
What does this mean? | Negative integer division surprising result | -0.039979 | 0 | 0 | 31,215 |
5,535,206 | 2011-04-04T06:25:00.000 | 3 | 0 | 1 | 0 | python,division,integer-division | 5,535,242 | 5 | false | 0 | 0 | When both values are integers when dividing Python uses Floor division. | 2 | 58 | 0 | In my application I encountered the following and was surprised by the results:
8/-7=-2 (both integers).
What does this mean? | Negative integer division surprising result | 0.119427 | 0 | 0 | 31,215 |
5,535,714 | 2011-04-04T07:33:00.000 | 3 | 0 | 0 | 0 | python,css,plone,xdv | 5,539,492 | 4 | false | 1 | 0 | Clicking save in the portal_css ZMI management screen will redo the merging and change the version number in the resources. | 2 | 3 | 0 | What is the correct method to manage css file versioning using collective.xdv?
Now I use nginx to serve css directly. I tried to import them in the css_registry, but if I change a file the merged css doesn't update, I mean, its version number (eg. the 4931 in rescsstylesheets-cachekey4931.css) doesn't get incremented.
... | Static css file and xdv | 0.148885 | 0 | 0 | 289 |
5,535,714 | 2011-04-04T07:33:00.000 | 3 | 0 | 0 | 0 | python,css,plone,xdv | 5,536,194 | 4 | false | 1 | 0 | that's not a version number. that's portal_css tool that merges and caches CSS files together for better performance.
While developing you have to enable CSS/JS debug in order to see changes in real time. Go to ZMI -> portal_css/javascript and check "debug mode" flag to be on.
If I'm not wrong, from plone 4.x you have ... | 2 | 3 | 0 | What is the correct method to manage css file versioning using collective.xdv?
Now I use nginx to serve css directly. I tried to import them in the css_registry, but if I change a file the merged css doesn't update, I mean, its version number (eg. the 4931 in rescsstylesheets-cachekey4931.css) doesn't get incremented.
... | Static css file and xdv | 0.148885 | 0 | 0 | 289 |
5,537,592 | 2011-04-04T11:07:00.000 | 0 | 0 | 0 | 0 | python,firefox,cookies | 5,537,633 | 4 | false | 0 | 0 | session cookies probably are kept in memory and deleted once the tab/browser is closed, never entering the database. | 2 | 8 | 0 | I'm trying to extract FF cookie from it's database (cookies.sqlite). However, seems that only cookies with expiration date can be found there (I am searching the one that expires when session ends). I even turned the "remember open tabs" feature of FF on.
I don't get it - what's the fundamental difference between them... | How to extract Firefox session cookie (python language preferred) | 0 | 0 | 0 | 5,439 |
5,537,592 | 2011-04-04T11:07:00.000 | 5 | 0 | 0 | 0 | python,firefox,cookies | 6,440,355 | 4 | false | 0 | 0 | Session cookies are stored in the sessionstore.js file.
This file is essentially a JSON object. If you parse it, look under windows[0].cookies to get an array of the session cookies.
Typically the only fields in each session cookie are {name, host, path, value}, but occasionally you see an httpOnly parameter. | 2 | 8 | 0 | I'm trying to extract FF cookie from it's database (cookies.sqlite). However, seems that only cookies with expiration date can be found there (I am searching the one that expires when session ends). I even turned the "remember open tabs" feature of FF on.
I don't get it - what's the fundamental difference between them... | How to extract Firefox session cookie (python language preferred) | 0.244919 | 0 | 0 | 5,439 |
5,538,280 | 2011-04-04T12:14:00.000 | 3 | 0 | 0 | 0 | python,parsing,redirect | 5,538,415 | 2 | false | 0 | 0 | You can not get hold of the redirection URL through parsing the HTML source code.
Redirections are triggered by the server and NOT by the client. You need to perform a HTTP request to the related URL and check the HTTP response of the server - in particular for the HTTP status code 304 (Redirection) and the new URL. | 1 | 6 | 0 | I made a little parser using HTMLparser and I would like to know where a link is redirected. I don't know how to explain this, so please look this example:
On my page I have a link on the source: http://www.myweb.com?out=147, which redirects to http://www.mylink.com. I can parse http://www.myweb.com?out=147 without any... | Determining redirected URL in Python | 0.291313 | 0 | 1 | 8,180 |
5,538,386 | 2011-04-04T12:24:00.000 | 1 | 1 | 0 | 0 | php,python,perl,performance,web-scraping | 5,538,463 | 3 | false | 0 | 0 | I would go with perl... I haired a rumor that was the language that google used initially... Python is a good performance language as well. | 1 | 4 | 0 | Say we have project that requires web scraping. (parsing strings (< 40) and scraping web pages (geting meta datas and such)
I am aware of that perl has great and suited cpan modules for this job, so i can take that way and don't bother myself that much. But i don't have a clue about speed and memory related stuff.
So, ... | Perl vs PHP to web scraping | 0.066568 | 0 | 0 | 2,213 |
5,538,747 | 2011-04-04T12:55:00.000 | 6 | 0 | 1 | 0 | python,compatibility | 5,538,940 | 4 | false | 1 | 0 | Hello
I had the same question because I began to learn Python 2 months ago.
So after reading some posts and informations, I decided to start with Python, 2.71, why?:
1/ Python 2.7.1 is really stable and has all the great libraries.
2/ It will be maintened for a long time for all the bugs (but not for the functions) so... | 3 | 2 | 0 | I wanted To learn how to program for the first time.
Because i`m mainly practice on IT and Security, I choose to start with Python.
But, As is started to learn Python 3, I came to realize that Non of the modules I wanted to use were ported to Python 3, and even Django (one of the main reasons I wanted to learn python)... | I left Python learning because of Python 2 vs 3 | 1 | 0 | 0 | 750 |
5,538,747 | 2011-04-04T12:55:00.000 | 3 | 0 | 1 | 0 | python,compatibility | 5,538,984 | 4 | false | 1 | 0 | +1 to all the replies you've received already. Yes start with Python 2, especially as you want to use libraries that are only available in 2. But whilst you are doing this, check what the differences are. The one that has bitten me is the change to print. Very minor but If I'd written all my prints in a python3 style i... | 3 | 2 | 0 | I wanted To learn how to program for the first time.
Because i`m mainly practice on IT and Security, I choose to start with Python.
But, As is started to learn Python 3, I came to realize that Non of the modules I wanted to use were ported to Python 3, and even Django (one of the main reasons I wanted to learn python)... | I left Python learning because of Python 2 vs 3 | 0.148885 | 0 | 0 | 750 |
5,538,747 | 2011-04-04T12:55:00.000 | 5 | 0 | 1 | 0 | python,compatibility | 5,538,809 | 4 | false | 1 | 0 | Python 2 and Python 3 are close enough that learning on the earlier version will give you a very solid grounding for migrating to 3 when it becomes more mainstream.
Abandoning a language just because it's transitioning to a new version is a bit silly, frankly. | 3 | 2 | 0 | I wanted To learn how to program for the first time.
Because i`m mainly practice on IT and Security, I choose to start with Python.
But, As is started to learn Python 3, I came to realize that Non of the modules I wanted to use were ported to Python 3, and even Django (one of the main reasons I wanted to learn python)... | I left Python learning because of Python 2 vs 3 | 0.244919 | 0 | 0 | 750 |
5,539,557 | 2011-04-04T13:58:00.000 | 0 | 1 | 1 | 0 | c++,python,boost,python-3.x,boost-python | 71,157,876 | 8 | false | 0 | 0 | In my case adding "Using Python : 3 etc." into user-config.jam in my home directory didn't work. I had to add the line into project-config.jam instead, which resides in the root directory of unpacked boost.
Specifically the line was:
using python : 3.9 : /usr/bin/python3 : /usr/include/python3.9 : /usr/lib ;
and the ve... | 1 | 30 | 0 | How does boost.python deal with Python 3? Is it Python 2 only? | Boost and Python 3.x | 0 | 0 | 0 | 44,365 |
5,539,736 | 2011-04-04T14:13:00.000 | 0 | 0 | 1 | 1 | python,executable,py2exe,cx-freeze | 29,426,136 | 6 | false | 0 | 0 | This is an old question, but one alternative is creating a virtual environment for Python, which can be as simple as python -m venv myenvname (Python 3.4). You can "install" packages into it the normal way (e.g. pip) without needing anything else. You'll end up with a folder you can move/delete at your leisure. | 1 | 32 | 0 | I have some .py files I wrote that I want to run on a different machine. The target machine does not have python installed, and I can't 'install' it by policy. What I can do is copy files over, run my stuff, and then remove them.
What I tried was to just take my development python folder over to the target machine an... | python: Can I run a python script without actually installing python? | 0 | 0 | 0 | 72,897 |
5,541,615 | 2011-04-04T16:43:00.000 | 3 | 0 | 0 | 1 | python,linux | 5,541,728 | 3 | true | 0 | 0 | You have two (classes of) choices:
You could build some distribution mechanism yourself.
You could use an existing tool to handle the distribution and storage.
In the simplest case, you write a program on each machine in your network that simply listens, processes and writes. You distribute from X to each machine in ... | 1 | 0 | 0 | I have a network of 100 machines, all running Ubuntu Linux.
On a continuous (streaming) basis, machine X is 'fed' with some real-time data. I need to write a python script that would get the data as input, load it in-memory, process it, and then save it to disk.
It's a lot of data, hence, I would ideally want to split ... | Fastest Way to Write Data To Individual Machines? | 1.2 | 0 | 0 | 179 |
5,544,629 | 2011-04-04T21:35:00.000 | 2 | 0 | 0 | 1 | python,celery | 50,170,855 | 14 | false | 1 | 0 | As far as I know Celery does not give API for examining tasks that are waiting in the queue. This is broker-specific. If you use Redis as a broker for an example, then examining tasks that are waiting in the celery (default) queue is as simple as:
connect to the broker
list items in the celery list (LRANGE command for... | 1 | 188 | 0 | How can I retrieve a list of tasks in a queue that are yet to be processed? | Retrieve list of tasks in a queue in Celery | 0.028564 | 0 | 0 | 188,607 |
5,544,634 | 2011-04-04T21:36:00.000 | 7 | 1 | 0 | 0 | python,performance,graphics,real-time-strategy | 5,544,725 | 2 | true | 0 | 1 | Performance may be an issue with heavy graphics/math processing. If so, see Panda3D, NumPy, Cython, and PyPy.
Use Pyglet, PyOpenGL with Pyglet, Panda3D (although you are writing in 2D, you can still use a 3D engine), or perhaps some other library.
There don't seem to be existing RTS libraries, but there are definitely ... | 2 | 3 | 0 | I am a great python fan. Recently I got an idea to write RTS engine and/or maybe a simple RTS game based upon this engine. There are a couple of things I need to think about and maybe you can give me some advice on these:
Performance. Most games are written in C++. Isn't python too slow for game engine? I am aiming on... | 2D RTS in Python? | 1.2 | 0 | 0 | 2,553 |
5,544,634 | 2011-04-04T21:36:00.000 | 3 | 1 | 0 | 0 | python,performance,graphics,real-time-strategy | 5,544,672 | 2 | false | 0 | 1 | I can answer your first two.
Python isn't too slow for games. That all games must be written in C++ is a myth. Sure C++ (or C) might give you the best performance, but it doesn't mean you're unable to write a game in another language.
Try PyGame: SDL bindings for Python. | 2 | 3 | 0 | I am a great python fan. Recently I got an idea to write RTS engine and/or maybe a simple RTS game based upon this engine. There are a couple of things I need to think about and maybe you can give me some advice on these:
Performance. Most games are written in C++. Isn't python too slow for game engine? I am aiming on... | 2D RTS in Python? | 0.291313 | 0 | 0 | 2,553 |
5,544,689 | 2011-04-04T21:42:00.000 | 1 | 0 | 0 | 0 | python,android | 11,871,778 | 1 | false | 1 | 0 | 1) Looks like this is pretty good way to manage your local & remote changes + support offline work. I don't think this is overkill
2) I think, you should cache user's changes locally with local timestamp until synchronizing is finished. Then server should manage all processing: track current version, commit and rollbac... | 1 | 4 | 0 | I'm in the planning phase of an Android app which synchronizes to a web app. The web side will be written in Python with probably Django or Pyramid while the Android app will be straightforward java. My goal is to have the Android app work while there is no data connection, excluding the social/web aspects of the app... | Android app database syncing with remote database | 0.197375 | 1 | 0 | 1,618 |
5,544,752 | 2011-04-04T21:48:00.000 | 6 | 0 | 1 | 0 | python | 5,544,781 | 5 | false | 0 | 0 | The if __name__ construct will let you easily re-use the functions and classes in the module in other Python scripts. If you don't do that, then everything in the module will run when it is imported.
If there's nothing in the script you want to reuse, then sure, just dump it all in there. I do that sometimes. If you la... | 3 | 45 | 0 | I have a lot of simple scripts that calculate some stuff or so. They consist of just a single module.
Should I write main methods for them and call them with the if __name__ construct, or just dump it all right in there?
What are the advantages of either method? | Should I use a main() method in a simple Python script? | 1 | 0 | 0 | 41,562 |
5,544,752 | 2011-04-04T21:48:00.000 | 10 | 0 | 1 | 0 | python | 5,545,789 | 5 | false | 0 | 0 | The other answers are good, but I wanted to add an example of why you might want to be able to import it: unit testing. If you have a few functions and then the if __name__=="__main__":, you can import the module for unit testing. Maybe you're better at this than me, but I find that my "simple scripts that couldn't pos... | 3 | 45 | 0 | I have a lot of simple scripts that calculate some stuff or so. They consist of just a single module.
Should I write main methods for them and call them with the if __name__ construct, or just dump it all right in there?
What are the advantages of either method? | Should I use a main() method in a simple Python script? | 1 | 0 | 0 | 41,562 |
5,544,752 | 2011-04-04T21:48:00.000 | 53 | 0 | 1 | 0 | python | 5,544,937 | 5 | false | 0 | 0 | I always write a main() function (appropriately named), and put nothing but command-line parsing and a call to main() in the if __name__ == '__main__' block. That's because no matter how silly, trivial, or single-purpose I originally expect that script to be, I always end up wanting to call it from another module at so... | 3 | 45 | 0 | I have a lot of simple scripts that calculate some stuff or so. They consist of just a single module.
Should I write main methods for them and call them with the if __name__ construct, or just dump it all right in there?
What are the advantages of either method? | Should I use a main() method in a simple Python script? | 1 | 0 | 0 | 41,562 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.