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
2,469,849
2010-03-18T12:45:00.000
1
0
1
1
python,pydev,enthought
9,306,753
7
false
0
0
I am running Python 3, so I had to make these changes to get python.exe as my interpreter. File: C:\EasyEclipse-for-LAMP-1.2.2.2\extensions\pydev-1.3.3\eclipse\plugins\org.python.pydev_1.3.3\PySrc\interpreterInfo.py Edit all occurrences of "print ..." to "print(...)" (the ... is whatever is being printed), so wrap it in parentheses. Comment out line 16, since True and False are considered keywords in Python 3. Save, and you should be able to successfully set C:\Python32\python.exe as the interpreter. I kept the default folders checked.
2
16
0
I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Distribution (EPD) I have installed, and can use all the packages that come with EPD. Can someone please tell me simple steps that I need to follow. If I click on autoconfig, it shows a bunch of folders with the path /System/Library/Frameworks/Python.Framework/Versions/2.5/... But I know that the Python that came with EPD is version 2.6.4, so autoconfig is not choosing EPD. Thanks for any help. UPDATE - solution If anyone else is interested in learning how to do this, see the first link in the answer by mlvljr below. Use the solution there EXCEPT that as suggested in the solution, Shift+Cmd+G, did not help me see inside the Python.app package. To look inside it, use the "gear" drop down menu in the Finder and choose "Show Package Contents"
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
0.028564
0
0
20,897
2,469,849
2010-03-18T12:45:00.000
12
0
1
1
python,pydev,enthought
4,060,609
7
false
0
0
Mac OS 10.6.4: Selecting the interpreter as /Library/Frameworks/Python.framework/Versions/2.7/Python did not work. I had to select /Library/Frameworks/Python.framework/Versions/2.7/bin/python
2
16
0
I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Distribution (EPD) I have installed, and can use all the packages that come with EPD. Can someone please tell me simple steps that I need to follow. If I click on autoconfig, it shows a bunch of folders with the path /System/Library/Frameworks/Python.Framework/Versions/2.5/... But I know that the Python that came with EPD is version 2.6.4, so autoconfig is not choosing EPD. Thanks for any help. UPDATE - solution If anyone else is interested in learning how to do this, see the first link in the answer by mlvljr below. Use the solution there EXCEPT that as suggested in the solution, Shift+Cmd+G, did not help me see inside the Python.app package. To look inside it, use the "gear" drop down menu in the Finder and choose "Show Package Contents"
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
1
0
0
20,897
2,470,121
2010-03-18T13:31:00.000
0
1
0
0
python,pydev
5,761,144
3
false
1
0
Well, as you didn't say what 'garbage' is showing, it's a bit hard to guess, but I believe you mean the __hash__, __str__, etc from the object class (is that it?) If that's the case, this has been dealt in the current nightly build (the '_' methods will still appear, but with lower priority, so, the methods you're probably more interested in are at the top)
1
5
0
I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time. I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php and Java. My question is the following: When i write classes in php or java i declare my methods and properties. I instantiate them somewhere else and use them. The autocompletion works great for java and php but with python, it seems to be always suggesting me a bunch of garbage and never the real object's methods from the class i instantiated. Is it the same for you ? Is it a limitation from pydev ? Am i doing something wrong ? Thank you in advance for pointing me in a direction. Matthieu.
Bad auto completion with python on pydev?
0
0
0
1,825
2,470,928
2010-03-18T15:17:00.000
1
1
1
0
python,dictionary,cpython
2,473,724
1
true
0
0
Observations, guesses, etc: Same happens in Python 2.x. dict_subscript implements the equivalent of the high_level dict.__getitem__ method and thus will be called whenever adict[somekey] appears other than on the LHS of an assignment in Python code. PyDict_GetItem is part of the C API. Perhaps it's an oversight that it hasn't been updated. Having read the dire comments at the start of PyDict_GetItem, I'd be using PyDict_GetItemWithError instead ;-) Perhaps you can do the C-level equivalent of my_getitem = getattr(my_dict, '__getitem__') once then call that. Perhaps you could raise a bug ticket or ask on comp.lang.python
1
1
0
I am reading cpython code for python 3k and I have noticed, that __missing__ is called only when dict_subscript is called, but not when PyDict_GetItem is used. What is the difference between those two methods and when each is called? If I pass an PyObject that is a subclass of dict and has __missing__ method, how can I force using it, since PyDict_GetItem doesn't do that.
cpython: when PyDict_GetItem is called and when dict_subscript?
1.2
0
0
698
2,470,971
2010-03-18T15:21:00.000
2
1
0
0
python,sockets
2,471,078
7
false
0
0
Are you on Linux? If so, perhaps your application could run netstat -lant (or netstat -lanu if you're using UDP) and see what ports are in use. This should be faster...
3
29
0
I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Since I'm only testing localhost, I think a timeout of about 50 milliseconds is more than ample for that. Unfortunately, the socket.setdefaulttimeout(50) method doesn't seem to work for some reason. How I can trim this down?
Fast way to test if a port is in use using Python
0.057081
0
1
46,722
2,470,971
2010-03-18T15:21:00.000
2
1
0
0
python,sockets
2,471,762
7
false
0
0
Simon B's answer is the way to go - don't check anything, just try to bind and handle the error case if it's already in use. Otherwise you're in a race condition where some other app can grab the port in between your check that it's free and your subsequent attempt to bind to it. That means you still have to handle the possibility that your call to bind will fail, so checking in advance achieved nothing.
3
29
0
I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Since I'm only testing localhost, I think a timeout of about 50 milliseconds is more than ample for that. Unfortunately, the socket.setdefaulttimeout(50) method doesn't seem to work for some reason. How I can trim this down?
Fast way to test if a port is in use using Python
0.057081
0
1
46,722
2,470,971
2010-03-18T15:21:00.000
14
1
0
0
python,sockets
2,471,039
7
true
0
0
How about just trying to bind to the port you want, and handle the error case if the port is occupied? (If the issue is that you might start the same service twice then don't look at open ports.) This is the reasonable way also to avoid causing a race-condition, as @eemz said in another answer.
3
29
0
I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Since I'm only testing localhost, I think a timeout of about 50 milliseconds is more than ample for that. Unfortunately, the socket.setdefaulttimeout(50) method doesn't seem to work for some reason. How I can trim this down?
Fast way to test if a port is in use using Python
1.2
0
1
46,722
2,471,804
2010-03-18T16:57:00.000
20
0
1
0
python,markdown,python-sphinx
17,228,308
12
false
0
0
Markdown and ReST do different things. RST provides an object model for working with documents. Markdown provides a way to engrave bits of text. It seems reasonable to want to reference your bits of Markdown content from your sphinx project, using RST to stub out the overall information architecture and flow of a larger document. Let markdown do what it does, which is allow writers to focus on writing text. Is there a way to reference a markdown domain, just to engrave the content as-is? RST/sphinx seems to have taken care of features like toctree without duplicating them in markdown.
2
240
0
I hate reST but love Sphinx. Is there a way that Sphinx reads Markdown instead of reStructuredText?
Using Sphinx with Markdown instead of reST
1
0
0
60,619
2,471,804
2010-03-18T16:57:00.000
1
0
1
0
python,markdown,python-sphinx
16,430,414
12
false
0
0
There is a workaround. The sphinx-quickstart.py script generates a Makefile. You can easily invoke Pandoc from the Makefile every time you'd like to generate the documentation in order to convert Markdown to reStructuredText.
2
240
0
I hate reST but love Sphinx. Is there a way that Sphinx reads Markdown instead of reStructuredText?
Using Sphinx with Markdown instead of reST
0.016665
0
0
60,619
2,472,221
2010-03-18T17:56:00.000
0
1
1
0
python
2,472,233
4
false
0
0
If you're on linux you can parse the output of the file command-line tool.
1
5
0
I have a folder full of files and I want to search some string inside them. The issue is that some files may be zip, exe, ogg, etc. Can I check somehow what kind of file is it so I only open and search through txt, PHP, etc. files. I can't rely on the file extension.
How to check if a file contains plain text?
0
0
0
7,602
2,473,783
2010-03-18T22:30:00.000
13
0
1
0
python,class,list,performance,append
2,474,076
7
false
0
0
There is nothing to circumvent: appending to a list is O(1) amortized. A list (in CPython) is an array at least as long as the list and up to twice as long. If the array isn't full, appending to a list is just as simple as assigning one of the array members (O(1)). Every time the array is full, it is automatically doubled in size. This means that on occasion an O(n) operation is required, but it is only required every n operations, and it is increasingly seldom required as the list gets big. O(n) / n ==> O(1). (In other implementations the names and details could potentially change, but the same time properties are bound to be maintained.) Appending to a list already scales. Is it possible that when the file gets to be big you are not able to hold everything in memory and you are facing problems with the OS paging to disk? Is it possible it's a different part of your algorithm that doesn't scale well?
1
59
0
I have a big file I'm reading from, and convert every few lines to an instance of an Object. Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping. This is a file that's around ~100MB so it isn't too large, but as the list grows larger, the looping slows down progressively. (I print the time for each lap in the loop). This is not intrinsic to the loop ~ when I print every new instance as I loop through the file, the program progresses at constant speed ~ it is only when I append them to a list it gets slow. My friend suggested disabling garbage collection before the while loop and enabling it afterward & making a garbage collection call. Did anyone else observe a similar problem with list.append getting slower? Is there any other way to circumvent this? I'll try the following two things suggested below. (1) "pre-allocating" the memory ~ what's the best way to do this? (2) Try using deque Multiple posts (see comment by Alex Martelli) suggested memory fragmentation (he has a large amount of available memory like I do) ~ but no obvious fixes to performance for this. To replicate the phenomenon, please run the test code provided below in the answers and assume that the lists have useful data. gc.disable() and gc.enable() helps with the timing. I'll also do a careful analysis of where all the time is spent.
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
1
0
0
50,901
2,474,224
2010-03-19T00:14:00.000
0
1
1
0
python,networking,programming-languages,robust
2,475,530
7
false
0
0
Python is up to the task (and better) for 1, 2 and 4. The best solution for 3 from what you describe would probably be to make your programs really open-source with GPL or BSD like licence. This way people will edit your super-cool sources (but often experienced programmers, not just script kiddies) and build on then but leave your name in for posterity.
3
9
0
I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that I needed one good, strong language to be good at. My questions: Is python powerful enough to handle most things that a typical programmer might do in his off-time? I have in mind things like complex stat generators based on user input for tabletop games, making small games, automate install processes, and build interactive websites, but probably a hundred things along those lines Does python handle networking tasks fairly well? Can python source be obfuscated, or is it going to be open-source by nature? The reason I ask this is because if I make something cool and distribute it, I don't want some idiot script kiddie to edit his own name in and say he wrote it And how popular is python, compared to other languages. Ideally, my language would be good and useful with help found online without extreme difficulty, but not so common that every idiot with computer knows python. I like the idea of knowing a slightly obscure language. Thanks a ton for any help you can provide.
Python for a hobbyist programmer ( a few questions)
0
0
0
861
2,474,224
2010-03-19T00:14:00.000
0
1
1
0
python,networking,programming-languages,robust
2,475,188
7
false
0
0
Points 1 and 2: HELL YEAH. Point 4: kind of. Python is good at some network stuff. It's not Java or C++. Just use zlib (zip library) and pickle (serialization) for everything, and look at xmlrpclib if you need IPC. Point 3: No. However, you can write C modules (for the performance critical, and hard-to-copy) parts of your code, and that would make it non-trivial to reverse-engineer.
3
9
0
I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that I needed one good, strong language to be good at. My questions: Is python powerful enough to handle most things that a typical programmer might do in his off-time? I have in mind things like complex stat generators based on user input for tabletop games, making small games, automate install processes, and build interactive websites, but probably a hundred things along those lines Does python handle networking tasks fairly well? Can python source be obfuscated, or is it going to be open-source by nature? The reason I ask this is because if I make something cool and distribute it, I don't want some idiot script kiddie to edit his own name in and say he wrote it And how popular is python, compared to other languages. Ideally, my language would be good and useful with help found online without extreme difficulty, but not so common that every idiot with computer knows python. I like the idea of knowing a slightly obscure language. Thanks a ton for any help you can provide.
Python for a hobbyist programmer ( a few questions)
0
0
0
861
2,474,224
2010-03-19T00:14:00.000
6
1
1
0
python,networking,programming-languages,robust
2,474,246
7
false
0
0
I think that Python is very powerful to do a lot of things, but just like Java and C++, it often depends on good third-party libraries. I come from a Java background but use Python for a lot of things, and it's been a fun ride. I've done things like statistics, and automation, not sure about the UI though that often depends on the toolkit more than the language. Python networking works well. I don't know if I'd use it to build a fast algorithmic trading system or a VOIP application, but for most intents and purposes, especially at higher levels of abstraction, it's fine and easy to use. You would need external libraries for things like SSH or FTP. Python is quite popular and has very good online support, active community, and major corporations (likeGoogle) that use it. I found the official online tutorial and reference to be excellent. I have to say that I disagree with the "every idiot with a computer" line. There's a difference between knowing a language and using it right, and that's true about every language, even natural ones :) Python does have a lot of functional elements that are not as trivial to use for people coming from a procedural background, so there's always room for growth. The one problem with Python compared to languages like C and Java is that it is not statically typed. This makes it much faster to write code, but also makes it *much easier) to make mistakes that can be quite nasty to debug. For instance, the same variable can contain a String reference at some point, and a reference to a list of strings at some other point.
3
9
0
I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that I needed one good, strong language to be good at. My questions: Is python powerful enough to handle most things that a typical programmer might do in his off-time? I have in mind things like complex stat generators based on user input for tabletop games, making small games, automate install processes, and build interactive websites, but probably a hundred things along those lines Does python handle networking tasks fairly well? Can python source be obfuscated, or is it going to be open-source by nature? The reason I ask this is because if I make something cool and distribute it, I don't want some idiot script kiddie to edit his own name in and say he wrote it And how popular is python, compared to other languages. Ideally, my language would be good and useful with help found online without extreme difficulty, but not so common that every idiot with computer knows python. I like the idea of knowing a slightly obscure language. Thanks a ton for any help you can provide.
Python for a hobbyist programmer ( a few questions)
1
0
0
861
2,474,554
2010-03-19T02:01:00.000
1
1
1
0
python,objective-c,pyobjc
2,475,334
2
true
0
0
There are only two kinds of programming languages:, the truism goes, the ones every one complains about and the ones no one uses. People who want to make programs don't choose a language because it's beautiful or clean; they choose it because it is supported, available, and not so awful that you just can't use it. When you see something you think you can improve, it can be very tempting to say I can fix that! and run right in, but in this case the cost is probably higher than is worth it. Programming languages that don't fill any bigger goal than being somewhat cleaner or a little more consistent tend not to catch on, as incremental advances in those areas aren't the things that you really, really need to improve the process of making software. Projects in obscure pet languages tend to die and not catch on, as the cost of contributing (learning someone's pet language that is new to you and that doesn't have broad support and documentation) is too high. If you are interested in language design and tinkering, this could be interesting for you. It's harder than it may seem—the designers of all the major languages have had to deal with a lot of tradeoffs in designing them, often sacrificing beauty and purity for practicality and compatibility. If, on the other hand, you want to write software, deal with the imperfect tools you were dealt.
2
1
0
I'm a fan of clean code. I like my languages to be able to express what I'm trying to do, but I like the syntax to mirror that too. For example, I work on a lot of programs in Objective-C for jailbroken iPhones, which patch other code using the method_setImplementation() function of the runtime. Or, in PyObjC, I have to use the syntax UIView.initWithFrame_(), which is also pretty awful and unreadable with the way the method names are structured. In both cases, the language does not support this in syntax. I've found three basic ways that this is done: Insane macros. Take a look at this "CaptainHook", it does what I'm looking for in a usable way, but it isn't quite clean and is a major hack. There's also "Logos", which implements a very nice syntax, but is written in Perl parsing my code with a ton of regular expressions. This scares me. I like the idea of adding a %hook ClassName, but not by using regular expressions to parse C or Objective-C. Finally, there is Cycript. This is an extension to JavaScript which interfaces with the Objective-C runtime and allows you to use Objective-C style code in your JavaScript, and inject that into other processes. This is likely the cleanest as it actually uses a parser for the JavaScript, but I'm not a huge fan of that language in general. Should, and how should, I create an extension to Python and Objective-C to allow me to do this? Is it worth writing a parser for my language to transform the syntax into something nicer, if it is only in a very specialized niche like this? Should I just live with the horrible syntax of the default Objective-C hooking or PyObjC?
Extending Python and Objective-C
1.2
0
0
775
2,474,554
2010-03-19T02:01:00.000
2
1
1
0
python,objective-c,pyobjc
2,474,626
2
false
0
0
If you don't have any experience in compiler or interpreter design my answer is an emphatic NO, it is one of the biggest challenges in computer science. If you do have experience my answer shifts to "that is a really dumb idea." Do you envision this becoming a large mature product that other people will want to use? If you do than go ahead, otherwise it will just distract you from writing great applications.
2
1
0
I'm a fan of clean code. I like my languages to be able to express what I'm trying to do, but I like the syntax to mirror that too. For example, I work on a lot of programs in Objective-C for jailbroken iPhones, which patch other code using the method_setImplementation() function of the runtime. Or, in PyObjC, I have to use the syntax UIView.initWithFrame_(), which is also pretty awful and unreadable with the way the method names are structured. In both cases, the language does not support this in syntax. I've found three basic ways that this is done: Insane macros. Take a look at this "CaptainHook", it does what I'm looking for in a usable way, but it isn't quite clean and is a major hack. There's also "Logos", which implements a very nice syntax, but is written in Perl parsing my code with a ton of regular expressions. This scares me. I like the idea of adding a %hook ClassName, but not by using regular expressions to parse C or Objective-C. Finally, there is Cycript. This is an extension to JavaScript which interfaces with the Objective-C runtime and allows you to use Objective-C style code in your JavaScript, and inject that into other processes. This is likely the cleanest as it actually uses a parser for the JavaScript, but I'm not a huge fan of that language in general. Should, and how should, I create an extension to Python and Objective-C to allow me to do this? Is it worth writing a parser for my language to transform the syntax into something nicer, if it is only in a very specialized niche like this? Should I just live with the horrible syntax of the default Objective-C hooking or PyObjC?
Extending Python and Objective-C
0.197375
0
0
775
2,476,234
2010-03-19T09:45:00.000
1
1
0
0
python,twisted,xmpp,irc,fifo
2,476,445
2
false
0
0
The fifo is the problem. Read from a socket instead. This will fit info the Twisted event-driven model much better. Trying to do things outside the control of the reactor is usually the wrong approach. ---- update based on feedback that the fifo is an external constraint, not avoidable ---- OK, the central issue is that you can not write code in the main (and only) thread of your Twisted app that makes blocking read calls to a fifo. That will cause the whole app to stall if there is nothing to read. So you're either looking at reading the fifo asynchronously, creating a separate thread to read it, or splitting the app in two. The last option is the simplest - modify the Twisted app so that it listens on a socket and write a separate little "forwarder" app that runs in a simple loop, reading the fifo and writing everything it hears to the socket.
2
4
0
Im trying to write some kind of multi protocol bot (jabber/irc) that would read messages from fifo file (one liners mostly) and then send them to irc channel and jabber contacts. So far, I managed to create two factories to connect to jabber and irc, and they seem to be working. However, I've problem with reading the fifo file - I have no idea how to read it in a loop (open file, read line, close file, jump to open file and so on) outside of reactor loop to get the data I need to send, and then get that data to reactor loop for sending in both protocols. I've been looking for information on how to do it in best way, but Im totally lost in the dark. Any suggestion/help would be highly appreciated. Thanks in advance!
Python (Twisted) - reading from fifo and sending read data to multiple protocols
0.099668
0
1
1,766
2,476,234
2010-03-19T09:45:00.000
3
1
0
0
python,twisted,xmpp,irc,fifo
2,478,970
2
false
0
0
You can read/write on a file descriptor without blocking the reactor as you do with sockets, by the way doesn't sockets use file descriptors? In your case create a class that implements twisted.internet.interfaces.IReadDescriptor and add to reactor using twisted.internet.interfaces.IReactorFDSet.addReader. For an example of IReadDescriptor implementation look at twisted.internet.tcp.Connection. I cannot be more specific because i never did by my self, but i hope this could be a start point.
2
4
0
Im trying to write some kind of multi protocol bot (jabber/irc) that would read messages from fifo file (one liners mostly) and then send them to irc channel and jabber contacts. So far, I managed to create two factories to connect to jabber and irc, and they seem to be working. However, I've problem with reading the fifo file - I have no idea how to read it in a loop (open file, read line, close file, jump to open file and so on) outside of reactor loop to get the data I need to send, and then get that data to reactor loop for sending in both protocols. I've been looking for information on how to do it in best way, but Im totally lost in the dark. Any suggestion/help would be highly appreciated. Thanks in advance!
Python (Twisted) - reading from fifo and sending read data to multiple protocols
0.291313
0
1
1,766
2,476,748
2010-03-19T11:18:00.000
0
1
0
0
java,c#,python,c++,bit-manipulation
2,477,111
7
false
0
0
I would recommend allocating a rather large buffer (4096 bytes at least) and flush that off to disk whenever it fills up. Using a one-byte buffer usually causes bad performance.
3
11
0
How can I write 'one bit' into a file stream or file structure each time? Is it possible to write to a queue and then flush it? Is it possible with C# or Java? This was needed when trying to implement an instance of Huffman coding. I can't write bits into files, so write them to a bitset and then (when compression was completed) write 8-bit piece of it each time (exclude last one).
Writing 'bits' to C++ file streams
0
0
0
5,699
2,476,748
2010-03-19T11:18:00.000
0
1
0
0
java,c#,python,c++,bit-manipulation
2,477,157
7
false
0
0
I did this once for huffman decoding and ended up writing the bits as chars and thus handling everything internally as a plain old C string. That way you don't have to worry about the trailing byte and it's human readable as well. Also checking bits is is easier since its just a matter of addressing the char array (binbuf[123] == '1') instead of having to fiddle with bits. Not the most optimized solution, but it solved my problem neatly. The obvious drawback is that this representation uses more memory.
3
11
0
How can I write 'one bit' into a file stream or file structure each time? Is it possible to write to a queue and then flush it? Is it possible with C# or Java? This was needed when trying to implement an instance of Huffman coding. I can't write bits into files, so write them to a bitset and then (when compression was completed) write 8-bit piece of it each time (exclude last one).
Writing 'bits' to C++ file streams
0
0
0
5,699
2,476,748
2010-03-19T11:18:00.000
0
1
0
0
java,c#,python,c++,bit-manipulation
2,478,818
7
false
0
0
The issue here is that many platforms do not have direct bit access. They group bits into a minimal package, often times the byte or word. Also, the protocol for stream devices does not facilitate transmission of individual bits. The common method to deal with individual bits is to pack them into the smallest portable and (addressable) accessible unit. The unused bits are usually set to zero. This can be accomplished with binary arithmetic operations (OR, AND, EXCLUSIVE-OR, NOT, etc.). With modern processors, bit twiddling slows down the machine and the performance. Memory is cheap and with large addressing spaces, justification for bit packing has become more difficult. Generally, bit packing is reserved for hardware oriented operations (and also transmission protocols). For example, if a processor's word capacity is 16 bits, the processor can probably handle 16 words faster than 16 bit manipulations in one word. Also, keep in mind that writing to and from memory is often faster than I/O from streams. Efficient systems buffer data in memory before transmitting the data. You may want to consider this technique in your designs. Reducing I/O operations will improve the performance of your program.
3
11
0
How can I write 'one bit' into a file stream or file structure each time? Is it possible to write to a queue and then flush it? Is it possible with C# or Java? This was needed when trying to implement an instance of Huffman coding. I can't write bits into files, so write them to a bitset and then (when compression was completed) write 8-bit piece of it each time (exclude last one).
Writing 'bits' to C++ file streams
0
0
0
5,699
2,476,931
2010-03-19T11:51:00.000
0
0
1
0
python,list,dictionary,iterable
4,110,683
5
false
0
0
I tried both examples with no success using python 2.7 To begin I created a file in C:\goat.text using notepad Next I tried the following import sys print>>"C:\goat.txt", "test" error AttributeError: 'str' object has no attribute 'write' print("test", file=open('C:\goat.txt', 'w')) SyntaxError: ("no viable alternative at input '='", ('C:\Users\mike\AppData\Local\Temp\sikuli-tmp5165417708161227735.py', 3, 18, 'print("test", file=open(\'C:\\goat.txt\', \'w\')) \n')) I've tried multiple variants annd can't solve this.
1
2
0
So lets say I have an incredibly nested iterable of lists/dictionaries. I would like to print them to a file as easily as possible. Why can't I just redirect print to a file? val = print(arg) gets a SyntaxError. Is there a way to access stdinput? And why does print take forever with massive strings? Bad programming on my side for outputting massive strings, but quick debugging--and isn't that leveraging the strength of an interactive prompt? There's probably also an easier way than my gripe. Has the hive-mind an answer?
Redirect print in Python: val = print(arg) to output mixed iterable to file
0
0
0
686
2,477,045
2010-03-19T12:08:00.000
1
0
0
0
python,image-manipulation
2,477,074
3
false
0
0
Why don't you simply store the images on the file system, and only store their references on the database. That's a lot more elegant, and won't consume loads of your database. Also, you won't have to use any kind of binary functions to read them from the DB, saving memory and loading time. Is there a very specific reason why you wanna store it on the DB? Cheers
1
3
0
I want to store the images related to a each person's profile in the DB and retrieve them when requested and save it as .jpg file - and display it to the users. How could I render the image data stored in the DB as an image and store it locally??
Storing and Retrieving Images from Database using Python
0.066568
1
0
19,327
2,479,902
2010-03-19T19:01:00.000
0
0
1
0
python,import,libraries,pep8
2,479,960
5
false
0
0
Imports happen when the module that contains the imports gets executed or imported, not when the functions are called. Ordinarily, I wouldn't worry about it. If you are encountering slowdowns, you might profile to see if your problem is related to this. If it is, you can check to see if your module can divided up into smaller modules. But if all the files are getting used by the same program, you'll just end up importing everything anyway.
4
2
0
I'm just wondering, I often have really long python files and imports tend to stack quite quickly. PEP8 says that the imports should always be written at the beginning of the file. Do all the imported libraries get imported when calling a function coded in the file? Or do only the necessary libraries get called? Does it make sense to worry about this? Is there no reason to import libraries within the functions or classes that need them?
Does python import all the listed libraries?
0
0
0
720
2,479,902
2010-03-19T19:01:00.000
1
0
1
0
python,import,libraries,pep8
2,479,950
5
false
0
0
Does it make sense to worry about this? No There no reason to import libraries within the functions or classes that need them. It's just slow because the import statement has to check to see if it's been imported once, and realize that it has been imported. If you put this in a function that's called frequently, you can waste some time with all the import checking.
4
2
0
I'm just wondering, I often have really long python files and imports tend to stack quite quickly. PEP8 says that the imports should always be written at the beginning of the file. Do all the imported libraries get imported when calling a function coded in the file? Or do only the necessary libraries get called? Does it make sense to worry about this? Is there no reason to import libraries within the functions or classes that need them?
Does python import all the listed libraries?
0.039979
0
0
720
2,479,902
2010-03-19T19:01:00.000
0
0
1
0
python,import,libraries,pep8
2,480,037
5
false
0
0
If a function inside a module is the only one to import a given other module (say you have a function sending tweets, only if some configuration option is on), then it makes sense to import that specific module in the function. Unless I see some profiling data proving otherwise, my guess is that the overhead of an import statement in a function is completely negligible.
4
2
0
I'm just wondering, I often have really long python files and imports tend to stack quite quickly. PEP8 says that the imports should always be written at the beginning of the file. Do all the imported libraries get imported when calling a function coded in the file? Or do only the necessary libraries get called? Does it make sense to worry about this? Is there no reason to import libraries within the functions or classes that need them?
Does python import all the listed libraries?
0
0
0
720
2,479,902
2010-03-19T19:01:00.000
2
0
1
0
python,import,libraries,pep8
2,479,982
5
false
0
0
The best place for imports is at the top of your file. That documents the dependencies in one place and makes errors from their absence appear earlier. The import itself actually occurs at the time of the import statement, but this seldom matters much. It is not typical that you have anything to gain by not importing a library until you are in a function or method that needs it. (There is never anything to gain by doing so inside the body of a class.) It is rare that you want optional dependencies and even rarer that this is the right technique to get them, though. Perhaps you can share a compelling use case?
4
2
0
I'm just wondering, I often have really long python files and imports tend to stack quite quickly. PEP8 says that the imports should always be written at the beginning of the file. Do all the imported libraries get imported when calling a function coded in the file? Or do only the necessary libraries get called? Does it make sense to worry about this? Is there no reason to import libraries within the functions or classes that need them?
Does python import all the listed libraries?
0.07983
0
0
720
2,481,287
2010-03-20T00:06:00.000
73
0
1
0
python,installation,boto
8,191,581
9
false
0
0
If necessary, install pip: sudo apt-get install python-pip Then install boto: pip install -U boto
2
51
0
So that I am able to work with it within my python scripts?
How do I install boto?
1
0
0
111,398
2,481,287
2010-03-20T00:06:00.000
5
0
1
0
python,installation,boto
2,481,306
9
false
0
0
switch to the boto-* directory and type python setup.py install.
2
51
0
So that I am able to work with it within my python scripts?
How do I install boto?
0.110656
0
0
111,398
2,481,417
2010-03-20T00:50:00.000
5
0
0
0
python,boto
6,861,411
2
false
0
0
I fixed same problem at Ubuntu using apt-get install python-boto
2
1
0
I have installed boto like so: python setup.py install; and then when I launch my python script (that imports moduls from boto) on shell, an error like this shows up: ImportError: No module named boto.s3.connection How to settle the matter?
Problem importing modul2s from boto
0.462117
0
1
3,095
2,481,417
2010-03-20T00:50:00.000
2
0
0
0
python,boto
2,481,420
2
false
0
0
This can happen if the Python script does not use your default python executable. Check the shebang on the first line of the script (on *nix) or the .py file association (on Windows) and run that against setup.py instead.
2
1
0
I have installed boto like so: python setup.py install; and then when I launch my python script (that imports moduls from boto) on shell, an error like this shows up: ImportError: No module named boto.s3.connection How to settle the matter?
Problem importing modul2s from boto
0.197375
0
1
3,095
2,481,421
2010-03-20T00:53:00.000
136
0
1
0
python
2,481,433
5
true
0
0
len is a function to get the length of a collection. It works by calling an object's __len__ method. __something__ attributes are special and usually more than meets the eye, and generally should not be called directly. It was decided at some point long ago getting the length of something should be a function and not a method code, reasoning that len(a)'s meaning would be clear to beginners but a.len() would not be as clear. When Python started __len__ didn't even exist and len was a special thing that worked with a few types of objects. Whether or not the situation this leaves us makes total sense, it's here to stay.
1
138
0
Is there any difference between calling len([1,2,3]) or [1,2,3].__len__()? If there is no visible difference, what is done differently behind the scenes?
Difference between len() and .__len__()?
1.2
0
0
112,175
2,482,270
2010-03-20T07:12:00.000
8
1
0
0
python,c,unit-testing,swig
2,489,948
2
true
0
1
I think that the exact solution depends on your code. Not all libraries are easily suitable for wrapping as a DLL. If your is, then ctypes is certainly the easiest way - just make a DLL out of your library and then test it with ctypes. An added bonus is that you now have your library conveniently wrapped as a standalone DLL which helps to decouple your application. Sometimes, however, a more thorough interaction will be required between your C code and the testing Python code. Then, it's probably best to hook it as an extension, for which SWIG is a pretty good tool that will automate away most things you'll find boring about the process.
1
25
0
I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any experience in the easiest way to do it? Some ideas include: Wrapping the code as a Python C extension using the Python API Wrap the C code using SWIG Add a DLL wrapper to the C code and load it into Python using ctypes Add a small XML-RPC server to the c-code and call it using xmlrpclib (yes, I know this seems a bit far-out!) Is there a canonical way of doing this? I'm going to be doing this quite a lot, with different C modules, so I'd like to find a way which is least effort.
Easiest way of unit testing C code with Python
1.2
0
0
12,704
2,482,399
2010-03-20T08:19:00.000
0
1
0
0
python,internationalization,trac
2,482,486
2
false
0
0
The stable release of trac, 0.11.X does not have support for localization. It is added in the upcoming 0.12 which is currently under development. Do you have 0.12 or did you download "latest stable" which is 0.11? In that case you will have to upgrade to get localization support. The trac site itself appears to be running 0.12 as it is localized.
1
1
0
How can I set default language for trac. There's nothing about i18n in trac.ini
Trac default language
0
0
0
2,028
2,483,924
2010-03-20T17:06:00.000
0
1
1
0
python,ruby,perl,module,dynamic-languages
2,484,750
7
false
0
0
Most scripting languages can handle this kind of thing (by running external programs written in other languages,) but it seems as if your best bet might be shell scripting of some kind (Windows users call this "batch scripting," but the DOS syntax is horrible and not recommended.) UNIX programmers have been freely mixing languages in this way for a long time. On Windows, you can install Cygwin to get a fully functional BASH shell. The shell was originally intended as a user interface, used to launch other programs or combine them in interesting ways. However, many shells (notably the Bourne shell or its modern descendant, BASH) are also fully-fledged programming languages. Each of your "modules" can be created as separate, standalone programs which will be run by the shell script.
4
1
0
Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought. To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module. In other words, which language "just works" with the most modules?
Which dynamic language can easily use libraries from other languages?
0
0
0
673
2,483,924
2010-03-20T17:06:00.000
3
1
1
0
python,ruby,perl,module,dynamic-languages
2,483,959
7
false
0
0
If you want to plug in a Perl module, the language which is best suited for this is Perl. Perl is able to represent the semantics and capabilities of code written in Perl correctly. This really shouldn't be a shock. If you have a self-contained program you want to call from another program in its own process, not constantly interacting, any of these languages can do that with programs written in whatever language. At that point, you aren't really using other languages inside a program but just calling other problems. There are several projects to combine various pairs and projects (like Parrot) that seek to provide a platform for a large range of languages for compatibility and projects (like .NET) that almost accidentally provide compatibility among previously-incompatible languages. However, I do not think most of these are as robust, mature, and suited for combining normal code as you would hope.
4
1
0
Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought. To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module. In other words, which language "just works" with the most modules?
Which dynamic language can easily use libraries from other languages?
0.085505
0
0
673
2,483,924
2010-03-20T17:06:00.000
0
1
1
0
python,ruby,perl,module,dynamic-languages
2,483,997
7
false
0
0
The Dynamic Language Runtime was specifically designed to allow one dynamic language to use objects and functions defined in another dynamic language. Currently Python and Ruby have DLR implementations, but I haven't heard anything about Perl. To use the DLR you need either .NET or Mono.
4
1
0
Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought. To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module. In other words, which language "just works" with the most modules?
Which dynamic language can easily use libraries from other languages?
0
0
0
673
2,483,924
2010-03-20T17:06:00.000
0
1
1
0
python,ruby,perl,module,dynamic-languages
2,483,932
7
false
0
0
all 3 languages have very good, clear facilities for just calling any executable in a subprocess (including executables like python somethingelse.py or ruby somethingelse.rb). use what you know best.
4
1
0
Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought. To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module. In other words, which language "just works" with the most modules?
Which dynamic language can easily use libraries from other languages?
0
0
0
673
2,484,215
2010-03-20T18:30:00.000
4
0
1
0
python,inheritance,overriding,parent
2,484,303
3
false
0
0
Using __foo names mangles the name of the method to make it more hassle to access it when you need to. I would recommend never using them, which makes things like testing go more smoothly. There is no private in Python, and if there was, it would prevent you from doing this anyhow. (This is the point of private stuff in languages that have it.) The common convention to indicate that an attribute is not part of the public interface of a class it to use a single leading underscore, like _foo. This is sufficient for making your code clear separating your internal details from your public API.
2
12
0
I have a private method def __pickSide(self): in a parent class that I would like to override in the child class. However, the child class still calls the inherited def __pickSide(self):. How can I override the function? The child class's function name is exactly the same as the parent's function name.
How do I override a parent class's functions in python?
0.26052
0
0
15,173
2,484,215
2010-03-20T18:30:00.000
5
0
1
0
python,inheritance,overriding,parent
2,484,252
3
false
0
0
The problem you're seeing is that the double underscores mangle the function name even in calls. This prevents polymorphism from working properly since the name it is mangled to is based on the name of the class the method is defined in, and not the name of the class of the object that is being referenced. Replacing the double underscores with something else will solve this.
2
12
0
I have a private method def __pickSide(self): in a parent class that I would like to override in the child class. However, the child class still calls the inherited def __pickSide(self):. How can I override the function? The child class's function name is exactly the same as the parent's function name.
How do I override a parent class's functions in python?
0.321513
0
0
15,173
2,484,578
2010-03-20T20:12:00.000
1
1
1
0
c#,python
2,484,600
10
false
0
0
The JITer, and the fact that it can produce tighter code due to it supporting static typing. The JITer can be worked around by using one of the non-CPython implementations, or dropping to i386 and using psyco, but the static typing can't be worked around as trivially (nor do I believe that it should be).
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
0.019997
0
0
7,557
2,484,578
2010-03-20T20:12:00.000
13
1
1
0
c#,python
2,484,624
10
false
0
0
Visual Studio - the best IDE out there. Of the statically typed languages in circulation, C# is very productive.
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
1
0
0
7,557
2,484,578
2010-03-20T20:12:00.000
0
1
1
0
c#,python
2,484,609
10
false
0
0
I've found it helpful to work with different languages, since they each have their strengths. Python is extremely powerful, but relies heavily on good coding conventions and practices to keep code maintainable. In particular, it does not enforce type safety or insulation, which means it is easy to abuse. C# is a modern object oriented language, with strong typing and other features to help enforce insulation and encapsulation. It's not as wildly flexible, but I've also found that larger C# programs are much easier to maintain (especially when you inherit them from other developers.)
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
0
0
0
7,557
2,484,578
2010-03-20T20:12:00.000
9
1
1
0
c#,python
2,484,595
10
true
0
0
There are lots of differences, advantages as well as disadvantages. I guess the main advantages would be along the lines of Excellent Windows integration, including access to all standard GUI functions and other libraries. JIT compilation, resulting in better performance than Python, in some or most circumstances. As has been pointed out, this is now also possible in Python. On Windows, the IDE support is arguably better for C#. Visual Studio is a well established and advanced development environment and the "Express" editions are free for personal use. In a non-Windows environment, it's probably a draw between different editors. The rest is basically up to personal preference (statically typed versus dynamically, C-like syntax or not, etc.).
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
1.2
0
0
7,557
2,484,578
2010-03-20T20:12:00.000
3
1
1
0
c#,python
2,485,085
10
false
0
0
C# is supported by Microsoft ;) (expecting comments) C# is typesafe which comes with its advantages. Nothing is better when you are developing windows applications. Its syntax is also very well designed. Code looks pretty good. Its worth learning because lots of code is written and is being written in it. It feels so good when you code in C# in Visual Studio. I am still searching for such a nice IDE for Python. With C# you can explore lots of interesting things .NET,WPF,WCF,XNA,ASP.NET,Jon Skeet's Blog... etc.
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
0.059928
0
0
7,557
2,484,578
2010-03-20T20:12:00.000
0
1
1
0
c#,python
2,484,612
10
false
0
0
Well, the ease of coding is debatable. I find C# easier to code when you factor in the help you get from teh IDEs (e.g. the free Visual Web Developer). So, portability is less of an issue if you factor in Mono. Performance can be better in some scenarios. I find the online documentation to be generally better in .NET. Have you considered IronPython? If you guys are willing to use one of the .Net distros that have the DLR in them (4.0's your best bet there, but some of the DLR betas are alright), then you can write C# code and Python code and have them work together w/o any difficulties outside naming conventions being a bit different.
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
0
0
0
7,557
2,484,578
2010-03-20T20:12:00.000
0
1
1
0
c#,python
2,484,650
10
false
0
0
C# can directly access pointers via "unmanaged code", which can give it a performance advantage in some situations.
7
10
0
I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python? The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the server is all written in C#. I'd love to do this, but I don't really have time to do multiple languages, and I was just after a few more reasons to justify taking C# over Python to myself. I'm doing this all self-taught as a hobby, btw
what are the advantages of C# over Python
0
0
0
7,557
2,485,901
2010-03-21T04:18:00.000
1
0
1
0
python,file,import,module
2,485,922
4
false
0
0
No, this isn't redundant - it's fine to import chores in both the main module and coolfunctions. The exact import mechanics of Python are complex (for example, module imports are only done once, meaning in your case that the actual parsing and loading of the chores module will only happen once, which is a nice optimization) but in general you shouldn't worry about it because it just works. Each Python file is a module, so your conf.py is also a module.
3
2
0
Let's assume I have a main script, main.py, that imports another python file with import coolfunctions and another: import chores Now, suppose coolfunctions also uses stuff from chores, hence I declare import chores inside coolfunctions. Since both main.py, and coolfunctions import chores ~ is this redundant? Is there any other way of doing this? Am I doing it correctly? I'm confused about how python projects should be structured in general. I have a "conf.py" file, that I import for a bunch of variables ~ is this a module or not? I load this conf file in multiple places as well.
How to import modules that are used in both the main code and a module correctly?
0.049958
0
0
481
2,485,901
2010-03-21T04:18:00.000
0
0
1
0
python,file,import,module
2,485,940
4
false
0
0
It is always the best practice to import all necessary modules in the file that uses them. Take for example: A.py contains: import coolfunctions B.py contains: import A Main.py contains: import B and uses functions that are defined in A.py (this is possible because by importing B, Main.py has imported everything that B imports) If in the future, you change B.py to function without needing to import A.py and therefore remove the import A, then your Main.py will suffer the loss of not having imported A.
3
2
0
Let's assume I have a main script, main.py, that imports another python file with import coolfunctions and another: import chores Now, suppose coolfunctions also uses stuff from chores, hence I declare import chores inside coolfunctions. Since both main.py, and coolfunctions import chores ~ is this redundant? Is there any other way of doing this? Am I doing it correctly? I'm confused about how python projects should be structured in general. I have a "conf.py" file, that I import for a bunch of variables ~ is this a module or not? I load this conf file in multiple places as well.
How to import modules that are used in both the main code and a module correctly?
0
0
0
481
2,485,901
2010-03-21T04:18:00.000
1
0
1
0
python,file,import,module
2,485,978
4
true
0
0
Each module X should import all (and only) the modules Y, Z, T, ... whose functionality it requires, without any worry about what other modules Fee, Fie, Foo ... (if any) may have already done part or all of those imports, or may be going to do so in the future. It would make a module extremely fragile (indeed, it would be the very opposite of modularity!) if each module had to worry about such subtle, "covert-channel" effects. What other modules Y, Z, T, ..., each module X chooses to import (if any) is part of X's implementation details, and shouldn't concern anybody except the developers who are coding, testing, or maintaining X. In order to ensure that this is the case, and that this clearly-best strategy of decoupling can and will fully be followed by sane code, Python "caches" modules as they get imported: a module is "loaded" only once per run of a program, the first time anybody imports it (or anything from inside it) -- all other imports use the same object obtained by that first loading, which Python keeps in a cache (which is specified as being the dict sys.modules, but you need to know that detail only for somewhat-advanced programming techniques... don't worry about it, 98.7% of the time -- just remember that "import is cheap"!-). Sure, a conf.py that you use from several other modules via import conf is definitely a module (you may think you're loading it multiple times, but you aren't unless you're using pretty advanced and deliberate techniques indeed for the purpose) -- why shouldn't it be?
3
2
0
Let's assume I have a main script, main.py, that imports another python file with import coolfunctions and another: import chores Now, suppose coolfunctions also uses stuff from chores, hence I declare import chores inside coolfunctions. Since both main.py, and coolfunctions import chores ~ is this redundant? Is there any other way of doing this? Am I doing it correctly? I'm confused about how python projects should be structured in general. I have a "conf.py" file, that I import for a bunch of variables ~ is this a module or not? I load this conf file in multiple places as well.
How to import modules that are used in both the main code and a module correctly?
1.2
0
0
481
2,486,348
2010-03-21T07:46:00.000
1
1
1
0
python,programming-languages,interpreter
2,487,912
8
true
0
0
Numerous template languages such as Cheetah, Django templates, Genshi, Mako, Mighty might serve as an example.
3
2
0
i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any programming language implemented in pure python which i can see as a reference ( or use directly ? ) -- i need simple language ( simple statements and ifs can do ) edit: sorry if i did not make myself clear but what i want is "a language to customize the running of program" , even though pypi seems a great option, what i am looking for is more simple which i can study and extend myself if need arise. my google searches pointing towards xml based langagues. ( BMEL , XForms etc ).
programming language implemented in pure python
1.2
0
0
1,368
2,486,348
2010-03-21T07:46:00.000
0
1
1
0
python,programming-languages,interpreter
2,486,375
8
false
0
0
Possibly Common Lisp (or any other Lisp) will be the best choice for that task. Because Lisp make it possible to easily extend host language with powerful macroses and construct DSL (domain specific language).
3
2
0
i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any programming language implemented in pure python which i can see as a reference ( or use directly ? ) -- i need simple language ( simple statements and ifs can do ) edit: sorry if i did not make myself clear but what i want is "a language to customize the running of program" , even though pypi seems a great option, what i am looking for is more simple which i can study and extend myself if need arise. my google searches pointing towards xml based langagues. ( BMEL , XForms etc ).
programming language implemented in pure python
0
0
0
1,368
2,486,348
2010-03-21T07:46:00.000
1
1
1
0
python,programming-languages,interpreter
2,486,403
8
false
0
0
Why not Python itself? With some care you can use eval to run user code. One of the good thing about interpreted scripting languages is that you don't need another extra scripting language!
3
2
0
i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any programming language implemented in pure python which i can see as a reference ( or use directly ? ) -- i need simple language ( simple statements and ifs can do ) edit: sorry if i did not make myself clear but what i want is "a language to customize the running of program" , even though pypi seems a great option, what i am looking for is more simple which i can study and extend myself if need arise. my google searches pointing towards xml based langagues. ( BMEL , XForms etc ).
programming language implemented in pure python
0.024995
0
0
1,368
2,486,737
2010-03-21T10:41:00.000
3
1
1
0
python
2,486,751
3
false
0
0
First you can try psyco, that may give you a speed up as much as 10x, but 2x is more typical If you can post the code up somewhere, perhaps someone can point out how to leverage numpy. If your task doesn't map well only numpy then cython is a good choice to convert a intensive function or two into C code just by adding a few cdefs. If you can show us the code (even just the hot spots) we can probably give you better advice. Perhaps you can modify your algorithm
1
0
0
I wrote a number crunching python code. The calculations involved can take hours. Is it possible somehow to compile it to binary? Thanks
Convert python script to binary executable
0.197375
0
0
2,921
2,487,033
2010-03-21T12:22:00.000
1
0
1
0
python,controls,port,device
21,833,149
4
false
0
0
but whatever.. someone will look for the answer at some point: I'm on a mac (osx 10.9).. I successfully installed libusb with mac ports, but was getting the "no backend available" message. It's because python can't find the usb dylibs. You have to add the path to your libusb to your $DYLD_LIBRARY_PATH (e.g. /opt/local/lib wherever your macport installed it). As soon I as I added it, pyusb worked fine.
1
7
0
i am using python on ubuntu 9.04 say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like if usb port id == A write data to device 1 if usb port id == B write data to device 2 any ideas....
usb device identification
0.049958
0
0
39,244
2,487,410
2010-03-21T14:29:00.000
1
0
1
0
debugging,ironpython
12,800,514
3
false
1
0
I love Eclipse. I learned it over several years while developing JAVA, and as soon as I found out there was a PyDev plug in that was enough for me. I would recommend seeing if there is a plugin for what ever IDE you are most comfortable with.
1
2
0
Is there a good debugger for IronPython?
A debugger for IronPython
0.066568
0
0
337
2,488,142
2010-03-21T18:17:00.000
2
0
0
0
python,django,mod-python
2,488,505
1
false
1
0
There are two obvious reasons to why this might happen: djangobb_forum is not on your Python path There is no __init__.py in the djangobb_forum folder If the code says from djangobb_forum import ... then you need to have the parent folder of djangobb_forum on your Python path.
1
4
0
I've installed Djangobb app on my server (Debian, mod_python) by cloning original source. The only things I've changed is database options in settings.py. All needed components are installed - syncdb query was executed right. But, when I'm trying to enter on my forum, it returns me error: ImproperlyConfigured: Error importing middleware django_authopenid.middleware: "No module named djangobb_forum.subscription" I've checked - djangobb_forum/subscription.py exist, so I don't know what can be wrong. Maybe someone had problems like that and know how to fix it? Sorry for my english.
Djangobb problem
0.379949
0
0
1,302
2,488,185
2010-03-21T18:25:00.000
1
0
1
1
python,pcap,packet-sniffers
2,488,246
1
true
0
0
Python 2.5 code should run fine unaltered on Python 2.6 (you'll just occasionaly get a DeprecationWarning for features which are changing in Python 3.x).
1
1
0
How do you end up running pypcap for python 2.6 on a mac? It seems that there hasn't been any new releases since 2.5 or am I just looking in the wrong places? I seem to be unable to install the 2.5 binary with the following error: You cannot install pcap 1.1 on this volume. pcap requires System Python 2.5 to install.
Pypcap for mac on python 2.6?
1.2
0
0
1,242
2,488,670
2010-03-21T20:55:00.000
1
0
1
0
python,algorithm,cluster-analysis,character-encoding
2,489,898
2
false
0
0
You should be able to treat your words as numerals in a strange base. For example, let's say you have a..z as your charset (26 characters), 4 character strings, and you want to distribute among equally 10 machines. Then there are a total of 26^4 strings, so each machine gets 26^4/10 strings. The first machine will get strings 0 through 26^4/10, the next 26^4/10 through 26^4/5, etc. To convert the numbers to strings, just write the number in base 26 using your charset as the numbers. So 0 is 'aaaa' and 26^4/10 = 2*26^3 + 15*26^2 + 15*26 +15 is 'cppp'.
1
1
1
My question is rather complicated for me to explain, as i'm not really good at maths, but i'll try to be as clear as possible. I'm trying to code a cluster in python, which will generate words given a charset (i.e. with lowercase: aaaa, aaab, aaac, ..., zzzz) and make various operations on them. I'm searching how to calculate, given the charset and the number of nodes, what range each node should work on (i.e.: node1: aaaa-azzz, node2: baaa-czzz, node3: daaa-ezzz, ...). Is it possible to make an algorithm that could compute this, and if it is, how could i implement this in python? I really don't know how to do that, so any help would be much appreciated
python parallel computing: split keyspace to give each node a range to work on
0.099668
0
0
260
2,488,710
2010-03-21T21:04:00.000
1
0
0
0
python,django,django-admin,shopping-cart,django-nonrel
2,488,729
3
false
1
0
Sounds like you want two related models - Item and Option. Item would contain the name of the item, and Option would contain the option - eg size - and the price of that option. You would then set up your admin to use an inline form for Option.
1
2
0
Basically I am writing a simple shopping cart. Each item can have multiple prices. (i.e. shirts where each size is priced differently). I would like to have a single price field in my admin panel, where when the first price is entered, an additional price field pops up. However I am kind of at a loss as to how to do this. What would be the best way to do this?
django admin - adding fields on the fly
0.066568
0
0
515
2,488,730
2010-03-21T21:10:00.000
30
0
1
0
python,c++,opengl,3d,pyopengl
2,489,409
5
true
0
1
It depends a LOT on the contents of your computer graphics course. If you are doing anything like the introductory course I've taught in the past, it's basically spinning cubes and spheres, some texture mapping and some vertex animation, and that's about it. In this case, Python would be perfectly adequate, assuming you can get around the Unpythonic (and, lets be honest, un-C++) OpenGL state-machine paradigm. For things like doing your matrix maths you can use Numpy, the core of which is written in C and is really quite quick. You'll be up and running faster, iterate faster and most likely have more fun. If, however, you are doing some hardcore, cutting edge, millions-of-triangles-per-scene-skinned-animated-everything computer graphics course, stick with C++. If your class has given you the choice it's probably a safe bet that Python will be ok. If you want to leverage your knowledge into a real job in computer graphics though, pretty much every game and graphics engine is written in C or C++, while Python (or Lua) is left as a scripting language.
2
15
0
I'm starting a computer graphics course, and I have to choose a language. Choices are between C++ and Python. I have no problem with C++, python is a work in progress. So i was thinking to go down the python road, using pyopengl for graphics part. I have heard though, that performance is an issue. Is python / pyopengl mature enough to challenge C++ on performance? I realize its a long shot, but I'd like to hear your thoughts, experiences on uses of pyopengl.
pyopengl: Could it replace c++?
1.2
0
0
10,480
2,488,730
2010-03-21T21:10:00.000
2
0
1
0
python,c++,opengl,3d,pyopengl
2,488,775
5
false
0
1
Python is an awesome language, but it's not the right tool for graphics. And if you want to do anything remotely advanced you'll have to use unpythonic libraries and will end up with ugly C code written in Python.
2
15
0
I'm starting a computer graphics course, and I have to choose a language. Choices are between C++ and Python. I have no problem with C++, python is a work in progress. So i was thinking to go down the python road, using pyopengl for graphics part. I have heard though, that performance is an issue. Is python / pyopengl mature enough to challenge C++ on performance? I realize its a long shot, but I'd like to hear your thoughts, experiences on uses of pyopengl.
pyopengl: Could it replace c++?
0.07983
0
0
10,480
2,489,299
2010-03-21T23:54:00.000
0
1
1
0
python,python-3.x
2,490,394
5
false
0
0
More iterators (in things like dict.keys()) will be a big boost for web applications. The core team will put more work into the new version. New books might focus on python 3 (see Dive into Python), but the real work is still done in python 2. Sooner or later, the big libraries (numpy, wx, django) will be ported. Until those big three switch, I can't see many people using python 3. But those aren't impossible projects to port. Once the big libraries are ported, the community will face a real choice. That's when it will start to catch on.
3
23
0
I have been learning a bit of Python 2 and Python 3 and it seems like Python 2 is overall better than Python 3. So that's where my question comes in. Are there any good reasons to actually switch over to python 3?
Will Python 3 ever catch on?
0
0
0
5,413
2,489,299
2010-03-21T23:54:00.000
32
1
1
0
python,python-3.x
2,489,398
5
true
0
0
On the whole, and even in most details, Python3 is better than Python2. The only area where Python 3 is lagging is with regards to 3rd party libraries. What makes Python great is not only its intrinsic characteristics as a language and its rather extensive standard library, but also the existence of a whole "eco-system" of libraries which support so many specific applications of the language. Several such libraries are, at the moment not fully ported to Python 3.x and this sometimes results in keeping people developing under Python 2.x. This situation may seem a bit like a chicken and egg problem: Application developers won't move to 3.x till the libraries "get there", libraries developers would rather only maintain one branch and are waiting in an attempt to time the porting to Py3k in a way that they can put the their Py2.x branches in maintenance shortly thereafter. This situation is somewhat of a testimony the satisfaction people have of Python 2.x (or phrased more negatively, to the lack of truly compelling incentives for a move to 3.x; while Py3k is better and poised for better things yet, as-is, it doesn't have any features that would prompt a move to 3.x "en masse".) This said, I believe the momentum is effectively in favor of Python 3. To back this up, I was about to mention the likelihood that Unladen Swallow be only ported to Py3k-only, providing some strong incentive for the move. But Alex Martelli has started answering this question, and is using this example. Obviously Alex speaks first-hand of these roadmap questions, please get it from the Master! A word of caution regarding Py3k versions: Be sure to use the most recent version (currently 3.1.2, soon 3.2.x will replace it as the most recent stable version). Beware that some folks (like me) occasionally use the expression "3.0" to reference the generic name for all Py3k (or even for the current version thereof). The short lived 3.0 version per-se is now "defunct" and of no interest but maybe forensic specialists ;-)
3
23
0
I have been learning a bit of Python 2 and Python 3 and it seems like Python 2 is overall better than Python 3. So that's where my question comes in. Are there any good reasons to actually switch over to python 3?
Will Python 3 ever catch on?
1.2
0
0
5,413
2,489,299
2010-03-21T23:54:00.000
6
1
1
0
python,python-3.x
2,489,395
5
false
0
0
The main thing holding Python 3.x back right now is the lack of third-party libraries. I'll be converting my code as soon as SciPy gets ported.
3
23
0
I have been learning a bit of Python 2 and Python 3 and it seems like Python 2 is overall better than Python 3. So that's where my question comes in. Are there any good reasons to actually switch over to python 3?
Will Python 3 ever catch on?
1
0
0
5,413
2,489,435
2010-03-22T00:48:00.000
1
1
1
0
python,math,perfect-square
2,489,474
24
false
0
0
You could binary-search for the rounded square root. Square the result to see if it matches the original value. You're probably better off with FogleBirds answer - though beware, as floating point arithmetic is approximate, which can throw this approach off. You could in principle get a false positive from a large integer which is one more than a perfect square, for instance, due to lost precision.
2
103
0
How could I check if a number is a perfect square? Speed is of no concern, for now, just working.
Check if a number is a perfect square
0.008333
0
0
193,572
2,489,435
2010-03-22T00:48:00.000
-1
1
1
0
python,math,perfect-square
2,489,814
24
false
0
0
Decide how long the number will be. take a delta 0.000000000000.......000001 see if the (sqrt(x))^2 - x is greater / equal /smaller than delta and decide based on the delta error.
2
103
0
How could I check if a number is a perfect square? Speed is of no concern, for now, just working.
Check if a number is a perfect square
-0.008333
0
0
193,572
2,489,620
2010-03-22T02:01:00.000
2
0
0
0
python,django,inheritance,django-models,django-orm
2,489,866
4
false
1
0
I agree about the roles solution, as depicted by Alex. What you have is not different subclasses of persons. You have different roles a person can have. But I hear you say: "hey, the ninja can have a property "numberOfStars", while a singer can have a property "highestNote". Same as for the interface: a ninja can have the method throwStar() and disappear(), while a singer can have sing() and getWasted(), and the bass player can have goFunky() and slapPop() What you have here is a case where your data model needs a very loose schema. So loose that, in fact, you have no schema at all. If the singer decides to take the bass and improvise a tune, that's fine. If he wants to act as a ninja, and you call throwStar, it will return an error, because he has no stars, but you could in principle, assign stars to a singer and make him throw stars. What you are venturing in is the world of ontologies, rather than schemas. You have a resource, which is "something" and this something can be some type, have some properties, etc. Presence of some properties can infer the type, or presence of some type can infer other types. You cannot describe this information easily with the simple django data model. What you would need is a context-aware, inferenced graph store, such as AllegroGraph, or implement your hacked up solution using rdflib.
2
14
0
I think this is a bit tricky, at least for me. :) So I have 4 models Person, Singer, Bassist and Ninja. Singer, Bassist and Ninja inherit from Person. The problem is that each Person can be any of its subclasses. e.g. A person can be a Singer and a Ninja. Another Person can be a Bassist and a Ninja. Another one can be all three. How should I organise my models? Help would be much appreciated!
Tricky model inheritance - Django
0.099668
0
0
2,669
2,489,620
2010-03-22T02:01:00.000
1
0
0
0
python,django,inheritance,django-models,django-orm
16,554,051
4
false
1
0
You could make all your professions (Ninja, Bassist....) inherit from Person in the models, and then use the function isinstance in the backend code to distinguish between the professions of a Person.
2
14
0
I think this is a bit tricky, at least for me. :) So I have 4 models Person, Singer, Bassist and Ninja. Singer, Bassist and Ninja inherit from Person. The problem is that each Person can be any of its subclasses. e.g. A person can be a Singer and a Ninja. Another Person can be a Bassist and a Ninja. Another one can be all three. How should I organise my models? Help would be much appreciated!
Tricky model inheritance - Django
0.049958
0
0
2,669
2,489,643
2010-03-22T02:08:00.000
1
0
0
0
python,qt4,pyqt4,qt-designer
2,494,652
4
false
0
1
You can run pyuic (or rather pyuic4) from hand, in your console. You can make your GUI using designer with Python, just as you would do it with C++. By the way: I have written all GUI stuff for my app (10k of code) by hand. I don't really like GUI designers and working with generated code, when you need to tweak something.
2
20
0
I'm new to Python and am starting to teach myself GUI programming (hopefully) using PyQT4.7 and Python 2.6 I just downloaded the whole PyQT/QT4 package (including QTDesigner) from the PyQT website, however it seems QTDesigner, which looks amazing to use as a newbie (since you can see all the attributes/properties/defaults etc) of each widget and visually edit the properties is great, but PyQT seems not to set QTDesigner to integrate directly with with PyQT and PyQTs python code generation scripts: i.e.: Hitting "View Code", tries to run the Designer->C++ script called (uic) instead of the pyuic.py script, etc. Is there a way to get QTDesigner to integrate closely with PyQT for code generation on the fly like it does with C++? If not, does that mean I have to code the entire QT GUI within my Python IDE and lookup all the documentation and boilerplate code for every widget? (seems very inefficient and inelegant compared to just having QTDesigner+Python integration). What is the customary toolchain//production flow of using Designer with PyQT? (If no direct integration is possible -- do python+pyQT users just skip using QTDesigner all together and manually write all the QT GUI code in python?) Any additional tips/suggestions for a PyQT newbie would be appreciated. Thanks! ps I know a bunch of you are probably going to tell me to just suck it up and code all the QT UI by hand, but if I use Designer while learning as asked above, please provide a way to do that so I can learn it more easily, thanks!
Using QTDesigner with PyQT and Python 2.6
0.049958
0
0
11,299
2,489,643
2010-03-22T02:08:00.000
0
0
0
0
python,qt4,pyqt4,qt-designer
3,595,979
4
false
0
1
QtDesigner uses uic.exe to generate on the fly C++ code. uic.exe is a command-line tool, it gets file names as input parameters. For integration with python, you can write a python program that uses pyuic.py, match it inputs with uic.exe's input (order, switchs etc.), convert it to an executable (using py2exe) and rename the executable to uic.exe. then replace it with uic.exe in Qt's bin directory (uic.exe dont exist in PyQt as I know). You should just be careful about input arguments of uic.exe and your hand-written macro (they should match together). I think your program will need to know python's path (in order to use pyuic). if you are using windows, you could obtain the path from registry.
2
20
0
I'm new to Python and am starting to teach myself GUI programming (hopefully) using PyQT4.7 and Python 2.6 I just downloaded the whole PyQT/QT4 package (including QTDesigner) from the PyQT website, however it seems QTDesigner, which looks amazing to use as a newbie (since you can see all the attributes/properties/defaults etc) of each widget and visually edit the properties is great, but PyQT seems not to set QTDesigner to integrate directly with with PyQT and PyQTs python code generation scripts: i.e.: Hitting "View Code", tries to run the Designer->C++ script called (uic) instead of the pyuic.py script, etc. Is there a way to get QTDesigner to integrate closely with PyQT for code generation on the fly like it does with C++? If not, does that mean I have to code the entire QT GUI within my Python IDE and lookup all the documentation and boilerplate code for every widget? (seems very inefficient and inelegant compared to just having QTDesigner+Python integration). What is the customary toolchain//production flow of using Designer with PyQT? (If no direct integration is possible -- do python+pyQT users just skip using QTDesigner all together and manually write all the QT GUI code in python?) Any additional tips/suggestions for a PyQT newbie would be appreciated. Thanks! ps I know a bunch of you are probably going to tell me to just suck it up and code all the QT UI by hand, but if I use Designer while learning as asked above, please provide a way to do that so I can learn it more easily, thanks!
Using QTDesigner with PyQT and Python 2.6
0
0
0
11,299
2,490,150
2010-03-22T05:27:00.000
0
1
0
0
python,cgi
2,490,241
2
false
0
0
There are a number of Python web frameworks which make this easier for you. Django, for example, has a built-in web server designed for testing out your application. However, if you're already using CGI, the easiest way to test it would be to run Apache. Configuring CGI for Apache is straightforward and there is a lot of good documentation.
1
0
0
Just wondering whats the best way to test Python CGI while developing a site? (I'm used to PHP for web dev so bear with me :P)
Best/Fastest Way to Test Python CGI locally?
0
0
0
893
2,490,291
2010-03-22T06:07:00.000
0
1
0
1
java,python,file-io
2,490,299
1
true
1
0
Performance-wise, for an I/O - syscall bound task such as you're mentioning, it's going to be a wash, most likely, depending a bit on the platform. Java tends to have better CPU usage (partly because a JVM can effectively use multiple cores on a multicore CPU on different threads, with CPython having problems with that; partly because of strong JIT abilities), but typically pays for them with higher RAM footprints (no big deal if you have 64GB of RAM laying around and not much else to do on the machine, say, but often an issue in other circumstances). If you specify the platform (Linux vs Windows vs ...), we might be able to offer more help. Edit: with processing required as light as the OP's mentioned in the Q's edit, there's really nothing either way in the CPU-load part of the task. Unfortunately I don't know what freebsd offers for "directory watching" (like Linux's inotify, etc).
1
1
0
I need to create daemon that will monitor certain directory and will process every file that's written to that particular path. My choice is either java or python. Did you guys have any experience using both technology? what is the best one? EDIT 1: files that will be processed is simple text file (one line with tab separated fields). I just need to move it to buffer and send to further to my php file. EDIT 2: It's for freebsd server
Performance Wise, Python VS JAVA For File Based Processing
1.2
0
0
1,498
2,490,592
2010-03-22T07:36:00.000
0
0
0
1
python,google-app-engine
2,491,775
3
false
1
0
Why not rewrite what your php script does in python? Php is a awful scripting language, and considering your thinking about calling it from inside a very powerful language, why not do it all in python
1
1
0
I wanto call a PHP script using Google App Engine. I just want to execute the script. The script updates a couple of databases on my webhost. But I guess Google App waits for the response. Is there a way by which I can start the script. The script takes some time and Google App might die during that time.
Use URL Fetch of Google App Engine just to call a php script
0
0
0
658
2,490,686
2010-03-22T08:04:00.000
2
0
1
0
python,tabs,indentation,spaces
2,490,727
4
false
0
0
This is something your editor should do for you. Most editors (try Notepad++ for example, it's free) will let you set whether hitting tab enters a tab character or a number of spaces. I'd recommend using two spaces instead of tab in all files (I find 4 is too much). Using spaces instead of tabs is better as it means that you can indent stuff using both the space & tab keys without worrying about messing up your files. If you have files that have a mix it isn't hard to write your own script to convert tabs to spaces
1
4
0
In Python, is there a mean to enforce the use of spaces or tabs indentation with a per file basis ? Well, perhaps "enforce" is too strong, more like a "recommendation". I keep receiving patch files with mixed indentation and this is annoying... (to say the least) Python itself can tell when there is a problem, but I am searching something to do that at the editor level, like it exists for the charset. Edit : Ok, my question wasn't clear, I am asking this because I keep receiving corrections and patches in any mix of tab/space you can imagine. I am using Mercurial as a DVCS, perhaps something exists at this level ?
Enforce "spaces" or "tabs" only in python files?
0.099668
0
0
3,387
2,490,715
2010-03-22T08:11:00.000
5
1
1
0
python,unit-testing
2,490,736
4
false
0
0
If you make functional programming then the unit is the function and I would recommend to unit test your functions
1
4
0
Hey - I'm new to python , and I'm having a hard time grasping the concept of Unit testing in python. I'm coming from Java - so unit testing makes sense because - well , there you actually have a unit - A Class. But a Python class is not necessarily the same as a Java class , and the way I use Python - as a scripting language - is more functional then OOP - So what do you "unit test" in Python ? A flow? Thanks!
Unit testing in python?
0.244919
0
0
941
2,491,222
2010-03-22T09:59:00.000
-2
0
1
0
python,file-rename
65,256,950
17
false
0
0
os.chdir(r"D:\Folder1\Folder2") os.rename(src,dst) #src and dst should be inside Folder2
1
585
0
I want to change a.txt to b.kml.
How to rename a file using Python
-0.023525
0
0
588,101
2,491,280
2010-03-22T10:08:00.000
0
0
0
1
python,django,google-app-engine
2,492,830
3
false
1
0
Re virtualenv question above: virtualenv have a parameter --python=PYTHON_EXE that you can point to the interpreter you'd like it to use. Running virtualenv without parameters or with an --help option whill show you which options you may pass it.
2
2
0
On my development system, I have Python 2.6, Django 1.1 and GAE. I have three projects running on Python 2.6 and Django 1.1. I have 1 project using GAE, Python 2.6 and Django 1.1. I have heard that my set-up for running GAE using Python 2.6 may create some head-scratching problems while deploying it on the production server, because GAE supports only Python 2.5, and using 2.6 is not recommended. Can I develop GAE application using Python 2.6? If not, what should I do? I am using Windows Vista as my development system. Please note : I don't want to disturb my other projects in development, which uses Python 2.6 and Django 1.1.
GAE, Python 2.5, Python 2.6 Side-by-side on windows
0
0
0
470
2,491,280
2010-03-22T10:08:00.000
0
0
0
1
python,django,google-app-engine
2,491,639
3
false
1
0
Unless you are using python 2.6 specific syntax/code your application is safe to run on GAE.
2
2
0
On my development system, I have Python 2.6, Django 1.1 and GAE. I have three projects running on Python 2.6 and Django 1.1. I have 1 project using GAE, Python 2.6 and Django 1.1. I have heard that my set-up for running GAE using Python 2.6 may create some head-scratching problems while deploying it on the production server, because GAE supports only Python 2.5, and using 2.6 is not recommended. Can I develop GAE application using Python 2.6? If not, what should I do? I am using Windows Vista as my development system. Please note : I don't want to disturb my other projects in development, which uses Python 2.6 and Django 1.1.
GAE, Python 2.5, Python 2.6 Side-by-side on windows
0
0
0
470
2,491,819
2010-03-22T11:35:00.000
9
0
1
0
python,class,init
2,491,843
12
false
0
0
__init__ doesn't return anything and should always return None.
1
140
0
I have a class with an __init__ function. How can I return an integer value from this function when an object is created? I wrote a program, where __init__ does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other member functions? If so how to do that? So far, I declared a variable outside class. and setting it one function doesn't reflect in other function ??
How to return a value from __init__ in Python?
1
0
0
195,099
2,492,490
2010-03-22T13:23:00.000
1
0
0
0
java,python,xml,marshalling,interop
2,492,599
2
true
1
0
As Ignacio says, XML is XML. On the python side, I recommend using lxml, unless you have more specific needs that are better met by another library. If you are restricted to the standard library, look at ElementTree or cElementTree, which are also excellent, and which inspired (and are functionally mostly equivalent to) lxml.etree. Edit: On closer look, it seems you are not just looking for XML, but for XML representations of objects. For this, check out lxml.objectify, or Amara. I haven't tried using them for interoperability with Java, but they're worth a try. If you're just looking for a way to do data exchange, you might also try custom JSON objects.
1
2
0
I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file). I need to be able read that XML later on with Java (JAXB) and unmarshall it. I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works would be great.
Python XML + Java XML interoperability
1.2
0
1
475
2,493,425
2010-03-22T15:23:00.000
2
0
1
0
python,list,dictionary,tuples
2,493,499
3
true
0
0
You can add a list to a tuple just like any other element. From a dictionary, you can access each element of the tuple by indexing it like so: d[key][0] and d[key][1]. Here is an example: >>> d = {} >>> d["b"] = ('b', [2]) >>> d["a"] = ('a', [1]) >>> for k in d: ... print(d[k][0], d[k][1]) ... ('a', [1]) ('b', [2])
1
0
0
How can i have a tuple that has a list as a value. F.x. if i want to have a structure like this. ( Somechar , Somelist[] ) And how would i iterate through a dictionary of these things?
Dictionaries with tuples that have lists as values
1.2
0
0
221
2,493,732
2010-03-22T16:01:00.000
1
0
1
0
python,finance,google-finance,stock
2,493,791
3
false
0
0
That will be hard to impossible. Little of this is exchange-traded (i.e. public) and even if it were, exchanges are unlikely to give data away for free. Sales of data now comprise more than half of total revenue for a number of exchanges.
1
4
0
I am looking for a resource to download fixed income data online, much like there is access to stock data from yahoo. At the very least I'd like the treasury bonds. I use python, but any help would be appreciated.
Fixed income data online
0.066568
0
0
2,698
2,494,288
2010-03-22T17:18:00.000
0
0
0
0
python,ctypes
2,494,539
2
false
0
1
You can also use ctypes.cast(buf, ctypes.c_void_p)
1
5
0
I am dealing with image buffers, and I want to be able to access data a few lines into my image for analysis with a c library. I have created my 8-bit pixel buffer in Python using create_string_buffer. Is there a way to get a pointer to a location within that buffer without re-creating a new buffer? My goal is to analyze and change data within that buffer in chunks, without having to do a lot of buffer creation and data copying. In this case, ultimately, the C library is doing all the manipulation of the buffer, so I don't actually have to change values within the buffer using Python. I just need to give my C function access to data within the buffer.
ctypes and pointer manipulation
0
0
0
3,210
2,494,468
2010-03-22T17:43:00.000
0
1
1
0
python,c,dll,distribution
2,540,638
6
false
0
1
There's a program called py2exe. I don't know if it's only available for Windows. Also, the latest version that I used does not wrap everything up into one .exe file. It creates a bunch of stuff that has to be distributed - a zip file, etc..
1
11
0
Hello fellow software developers. I want to distribute a C program which is scriptable by embedding the Python interpreter. The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding. I'm looking for a solution where I distribute only the following components: my program executable and its libraries the Python library (dll/so) a ZIP-file containing all necessary Python modules and libraries. How can I accomplish this? Is there a step-by-step recipe for that? The solution should be suitable for both Windows and Linux. Thanks in advance.
How to create an application which embeds and runs Python code without local Python installation?
0
0
0
5,060
2,494,508
2010-03-22T17:49:00.000
1
0
1
0
python,nlp
2,494,560
6
false
0
0
If neos recommendation is also unpractical, I would try something like this: In many languages there are some keywords which are in many sentences and are often not found in other languages. Example: "The" in English, "der", "die", "das" in German, .... Find such words and try to find them in your texts. It can be a little fuzzy at last -- for example, when you find "the" and "der" -- it could be a German text containing some English sentences in it. At least with enough words from your target languages you could come to a high hit-rate.
1
20
0
I have a list of articles, and each article has its own title and description. Unfortunately, from the sources I am using, there is no way to know what language they are written in. Furthermore, the text is not entirely written in 1 language; almost always English words are present. I reckon I would need dictionary databases stored on my machine, but it feels a bit impractical. What would you suggest I do?
Recognizing language of a short text?
0.033321
0
0
6,940
2,495,350
2010-03-22T20:09:00.000
7
1
0
0
python,ruby-on-rails,artificial-intelligence,prolog
2,497,026
5
false
1
0
The selection of language is completely irrelevant, all other things being equal. If you're trying to do X and there's a library for it in language Y and meshes well with your Web-based framework, then use it. Without knowing more about what specific areas of AI you're interested in, the question is far too vague to be answered with any more specificity.
2
4
0
A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that environment), but using Google there seems to be a preliminary ProLog implementation for both. Any suggestions on modern (open source) web languages (like Python or Ruby) in combination with AI?
Python or Ruby for webbased Artificial Intelligence?
1
0
0
3,942
2,495,350
2010-03-22T20:09:00.000
0
1
0
0
python,ruby-on-rails,artificial-intelligence,prolog
2,498,323
5
false
1
0
You could also use Scala (which is a bit functional and runs on the JVW) and the existing Lift framework for web-stuff.
2
4
0
A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that environment), but using Google there seems to be a preliminary ProLog implementation for both. Any suggestions on modern (open source) web languages (like Python or Ruby) in combination with AI?
Python or Ruby for webbased Artificial Intelligence?
0
0
0
3,942
2,497,449
2010-03-23T03:47:00.000
4
0
1
0
python,matplotlib
2,497,667
5
false
0
0
Why not just make the x value some auto-incrementing number and then change the label? --jed
1
11
1
I am using matplotlib for a graphing application. I am trying to create a graph which has strings as the X values. However, the using plot function expects a numeric value for X. How can I use string X values?
Plot string values in matplotlib
0.158649
0
0
48,768
2,498,009
2010-03-23T06:36:00.000
4
1
1
0
java,.net,c++,python,encryption
2,498,054
6
true
0
0
How can I accomplish this, and WHAT IS the BEST encryption way to do it, if applicable? tar and gzip the directory. Generate a random bit stream of equal size to the file Run bitwise XOR on the streams Only truly secure method is a truly random one time pad.
2
4
0
I need to programatically encrypt a directory of files, like in a .zip or whatever. Preferably password protected obviously. How can I accomplish this, and WHAT IS the BEST encryption way to do it, if applicable? Programming language doesn't matter. I am dictioned in all syntax.
Best way to encrypt a directory of files?
1.2
0
0
4,494
2,498,009
2010-03-23T06:36:00.000
3
1
1
0
java,.net,c++,python,encryption
2,498,034
6
false
0
0
I still say 7-zip is the answer. It hasn't been "cracked".
2
4
0
I need to programatically encrypt a directory of files, like in a .zip or whatever. Preferably password protected obviously. How can I accomplish this, and WHAT IS the BEST encryption way to do it, if applicable? Programming language doesn't matter. I am dictioned in all syntax.
Best way to encrypt a directory of files?
0.099668
0
0
4,494
2,499,491
2010-03-23T11:37:00.000
1
0
1
0
python,memory,buffer
2,500,096
8
false
0
0
You can also set up persistent shared memory area and have one program write to it and the other read it. However, setting up such things is somewhat dependent on the underlying O/S.
4
1
0
Let's imagine a situation: I have two Python programs. The first one will write some data (str) to computer memory, and then exit. I will then start the second program which will read the in-memory data saved by the first program. Is this possible?
Reading and writing to/from memory in Python
0.024995
0
0
4,514
2,499,491
2010-03-23T11:37:00.000
1
0
1
0
python,memory,buffer
2,499,513
8
false
0
0
No. Once the first program exits, its memory is completely gone. You need to write to disk.
4
1
0
Let's imagine a situation: I have two Python programs. The first one will write some data (str) to computer memory, and then exit. I will then start the second program which will read the in-memory data saved by the first program. Is this possible?
Reading and writing to/from memory in Python
0.024995
0
0
4,514
2,499,491
2010-03-23T11:37:00.000
2
0
1
0
python,memory,buffer
2,499,521
8
false
0
0
Store you data into "memory" using things like databases, eg dbm, sqlite, shelve, pickle, etc where your 2nd program can pick up later.
4
1
0
Let's imagine a situation: I have two Python programs. The first one will write some data (str) to computer memory, and then exit. I will then start the second program which will read the in-memory data saved by the first program. Is this possible?
Reading and writing to/from memory in Python
0.049958
0
0
4,514
2,499,491
2010-03-23T11:37:00.000
1
0
1
0
python,memory,buffer
2,499,529
8
false
0
0
The first one will write some data (str) to computer memory, and then exit. The OS will then ensure all that memory is zeroed before any other program can see it. (This is an important security measure, as the first program may have been processing your bank statement or may have had your password). You need to write to persistent storage - probably disk. (Or you could use a ramdisk, but that's unlikely to make any difference to real-world performance). Alternatively, why do you have 2 programs? Why not one program that does both tasks?
4
1
0
Let's imagine a situation: I have two Python programs. The first one will write some data (str) to computer memory, and then exit. I will then start the second program which will read the in-memory data saved by the first program. Is this possible?
Reading and writing to/from memory in Python
0.024995
0
0
4,514
2,501,457
2010-03-23T15:58:00.000
389
0
1
0
python,data-structures,heap,recursive-datastructures
2,501,527
19
false
0
0
The easiest way is to invert the value of the keys and use heapq. For example, turn 1000.0 into -1000.0 and 5.0 into -5.0.
3
362
0
Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?
What do I use for a max-heap implementation in Python?
1
0
0
215,327
2,501,457
2010-03-23T15:58:00.000
55
0
1
0
python,data-structures,heap,recursive-datastructures
44,352,853
19
false
0
0
The easiest and ideal solution Multiply the values by -1 There you go. All the highest numbers are now the lowest and vice versa. Just remember that when you pop an element to multiply it with -1 in order to get the original value again.
3
362
0
Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?
What do I use for a max-heap implementation in Python?
1
0
0
215,327
2,501,457
2010-03-23T15:58:00.000
5
0
1
0
python,data-structures,heap,recursive-datastructures
2,501,572
19
false
0
0
If you are inserting keys that are comparable but not int-like, you could potentially override the comparison operators on them (i.e. <= become > and > becomes <=). Otherwise, you can override heapq._siftup in the heapq module (it's all just Python code, in the end).
3
362
0
Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?
What do I use for a max-heap implementation in Python?
0.052583
0
0
215,327
2,501,492
2010-03-23T16:02:00.000
4
0
0
0
python,ironpython
2,501,635
1
true
0
0
If you are writing "100% pure Python", you can do everything that CPython can do in IronPython. The problem comes in when you want to use a third-party package. Many of them will have written their performance-intensive portions in C, and rely on the Python/C API (e.g. NumPy). As a glue language for hooking together .NET components, IronPython is great.
1
5
0
What can be done in Cpython that can not be done in IronPython?
What can be done in Cpython that can not be done in IronPython?
1.2
0
0
233
2,502,243
2010-03-23T17:40:00.000
0
0
1
0
python,packet-capture,pcap
9,111,171
2
false
0
0
You could also try sudo apt-get install libpcap-dev
1
2
0
When I check the attributes available to the module pcap, I expect to see something like [ ...snip... 'dltvalue', 'findalldevs', 'lookupdev', 'lookupnet', 'ntoa', 'pcapObject', 'pcapObjectPtr'] With note on pcapObject. However, all I get when running dir(pcap) is [ ... snip... 'copyright', 'doc', 'file', 'license', 'name', 'url', 'version', 'bpf', 'dltoff', 'ex_name', 'lookupdev', 'pcap', 'sys'] Noting the lack of pcapObject. Why is this? What could cause this?
missing elements from pcap?
0
0
0
2,330