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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
931,995 | 2009-05-31T12:48:00.000 | 2 | 0 | 1 | 0 | python,math,floating-point | 932,021 | 9 | false | 0 | 0 | This is normal. I would expect log10 to be more accurate then log(x, y), since it knows exactly what the base of the logarithm is, also there may be some hardware support for calculating base-10 logarithms. | 2 | 15 | 0 | I work daily with Python 2.4 at my company. I used the versatile logarithm function 'log' from the standard math library, and when I entered log(2**31, 2) it returned 31.000000000000004, which struck me as a bit odd.
I did the same thing with other powers of 2, and it worked perfectly. I ran 'log10(2**31) / log10(2)' and I got a round 31.0
I tried running the same original function in Python 3.0.1, assuming that it was fixed in a more advanced version.
Why does this happen? Is it possible that there are some inaccuracies in mathematical functions in Python? | Inaccurate Logarithm in Python | 0.044415 | 0 | 0 | 10,703 |
932,328 | 2009-05-31T16:01:00.000 | 42 | 0 | 1 | 0 | python,operators | 932,347 | 6 | true | 0 | 0 | No, you can't create new operators. However, if you are just evaluating expressions, you could process the string yourself and calculate the results of the new operators. | 2 | 90 | 0 | I would like to define my own operator. Does python support such a thing? | Python: defining my own operators? | 1.2 | 0 | 0 | 62,864 |
932,328 | 2009-05-31T16:01:00.000 | 10 | 0 | 1 | 0 | python,operators | 932,385 | 6 | false | 0 | 0 | If you intend to apply the operation on a particular class of objects, you could just override the operator that matches your function the closest... for instance, overriding __eq__() will override the == operator to return whatever you want. This works for almost all the operators. | 2 | 90 | 0 | I would like to define my own operator. Does python support such a thing? | Python: defining my own operators? | 1 | 0 | 0 | 62,864 |
932,818 | 2009-05-31T20:44:00.000 | 11 | 0 | 1 | 0 | python | 932,829 | 9 | false | 0 | 0 | Variable names persist in the compiled code (that's how e.g. the dir built-in can work), but the mapping that's there goes from name to value, not vice versa. So if there are several variables all worth, for example, 23, there's no way to tell them from each other base only on the value 23 . | 1 | 32 | 0 | Is there a way to know, during run-time, a variable's name (from the code)?
Or do variable's names forgotten during compilation (byte-code or not)?
e.g.:
>>> vari = 15
>>> print vari.~~name~~()
'vari'
Note: I'm talking about plain data-type variables (int, str, list etc.) | How to retrieve a variable's name in python at runtime? | 1 | 0 | 0 | 24,966 |
933,214 | 2009-06-01T00:43:00.000 | 5 | 0 | 1 | 0 | python-3.x,frontend | 933,225 | 5 | false | 0 | 0 | I'm not using Python 3 "in production", yet, but in playing around with it I've found that print being a function is a superb idea -- for example, I can easily put it in a lambda now, where in 2.* I have to use sys.stdout.write("%s\n" % foo), a bit crufty. Plus, the syntax for such tweaks as using an output file different from sys.stdout or removing the final \n is so much more readable than Python 2.*'s!
BTW, with is also in recent Python 2.* versions, it's not a Python 3 - exclusive. | 3 | 3 | 0 | I've recently did some web design as a hobby with a primary motivation to learn interesting things. It was certainly nice to learn Python, but I found out there has just been a Great Python Rewrite too late, so I had to learn both Python 3 and 2.6 essentially.
I'm a newbie, so I'd like people to share what they think the strengths/weaknesses of Python 3 are from the perspective of those who do end-user programming rather than language designers. My question would be more of what people are actually liking to the point of using, or shunning as being unproductive or unpythonic.
For me, with statement is definite plus, while breaking print operator is definitely minus.
Clarification edit: there are many posts that ask whether one should learn Python 2 or 3 or whether there is any difference. I see my question is different: the feedback from people who for whatever reason made the choice of using Python 3 but might have an opinion about what works better, what not.
Another clarification: It has been pointed in the answers that with is backported to 2.*. Apologies. | What are the used/unused features of Python 3? | 0.197375 | 0 | 0 | 538 |
933,214 | 2009-06-01T00:43:00.000 | 2 | 0 | 1 | 0 | python-3.x,frontend | 933,221 | 5 | false | 0 | 0 | I think everything they did was for the best, in the long run. They removed a lot of the deprecated ways to do things, thus enforcing "There's Only One Way to Do It" and increasing consistency. Also, the with statement is awesome.
The obvious problem with using Python 3 is its lack of support for a lot of [big] libraries out there (such as Django). If none of your libraries break with Python 3, there's no reason not to use it. | 3 | 3 | 0 | I've recently did some web design as a hobby with a primary motivation to learn interesting things. It was certainly nice to learn Python, but I found out there has just been a Great Python Rewrite too late, so I had to learn both Python 3 and 2.6 essentially.
I'm a newbie, so I'd like people to share what they think the strengths/weaknesses of Python 3 are from the perspective of those who do end-user programming rather than language designers. My question would be more of what people are actually liking to the point of using, or shunning as being unproductive or unpythonic.
For me, with statement is definite plus, while breaking print operator is definitely minus.
Clarification edit: there are many posts that ask whether one should learn Python 2 or 3 or whether there is any difference. I see my question is different: the feedback from people who for whatever reason made the choice of using Python 3 but might have an opinion about what works better, what not.
Another clarification: It has been pointed in the answers that with is backported to 2.*. Apologies. | What are the used/unused features of Python 3? | 0.07983 | 0 | 0 | 538 |
933,214 | 2009-06-01T00:43:00.000 | 1 | 0 | 1 | 0 | python-3.x,frontend | 933,229 | 5 | false | 0 | 0 | This is really subjective. Python3.x is certainly an improvement over 2.x. It contains long anticipated changes like: Dictionary comprehensions, ordered dictionary, more powerful string formatting...etc Not to mention cleaner library. | 3 | 3 | 0 | I've recently did some web design as a hobby with a primary motivation to learn interesting things. It was certainly nice to learn Python, but I found out there has just been a Great Python Rewrite too late, so I had to learn both Python 3 and 2.6 essentially.
I'm a newbie, so I'd like people to share what they think the strengths/weaknesses of Python 3 are from the perspective of those who do end-user programming rather than language designers. My question would be more of what people are actually liking to the point of using, or shunning as being unproductive or unpythonic.
For me, with statement is definite plus, while breaking print operator is definitely minus.
Clarification edit: there are many posts that ask whether one should learn Python 2 or 3 or whether there is any difference. I see my question is different: the feedback from people who for whatever reason made the choice of using Python 3 but might have an opinion about what works better, what not.
Another clarification: It has been pointed in the answers that with is backported to 2.*. Apologies. | What are the used/unused features of Python 3? | 0.039979 | 0 | 0 | 538 |
933,822 | 2009-06-01T07:14:00.000 | 0 | 1 | 0 | 0 | c#,python,ruby,ironpython,ironruby | 933,988 | 3 | false | 1 | 0 | IronPython 2.0 has a sample compiler called PYC on Codeplex.com/ironpython which can create DLL's (and applications if you need them too).
IronPython 2.6 has a newer version of PYC under Tools\script.
Cheers,
Davy | 2 | 3 | 0 | Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will find the embedded resources? | Packaging script source files in IronPython and IronRuby | 0 | 0 | 0 | 520 |
933,822 | 2009-06-01T07:14:00.000 | 1 | 1 | 0 | 0 | c#,python,ruby,ironpython,ironruby | 934,609 | 3 | false | 1 | 0 | You could add custom import hook that looks for embedded resources when an import is executed. This is slightly complex and probably not worth the trouble.
A better technique would be to fetch all of the embedded modules at startup time, execute them with the ScriptEngine and put the modules you have created into the sys.modules dictionary associated with the engine. This automatically makes them available for import by Python code executed by the engine. | 2 | 3 | 0 | Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will find the embedded resources? | Packaging script source files in IronPython and IronRuby | 0.066568 | 0 | 0 | 520 |
934,221 | 2009-06-01T10:08:00.000 | 2 | 0 | 0 | 0 | python | 934,709 | 1 | false | 0 | 0 | Why to pass connection itself? Maybe build a class that handles all the DB-operation and just pass this class' instance around, calling it's methods to perform selects, inserts and all that DB-specific code? | 1 | 0 | 0 | I am having a script which makes a db connection and pereform some select operation.accroding to the fetch data i am calling different functions which also perform db operations.How can i pass db connection to the functions which are being called as i donot want to make new connection | python db connection | 0.379949 | 1 | 0 | 515 |
935,378 | 2009-06-01T15:42:00.000 | 1 | 0 | 1 | 0 | python,methods | 935,413 | 7 | false | 0 | 0 | These methods were named as such to reduce the possibility of naming collisions. | 4 | 38 | 0 | What is the difference between __method__, method and _method__?
Is there any or for some random reason people thought that __doc__ should be right like that instead of doc. What makes a method more special than the other? | Difference between "__method__" and "method" | 0.028564 | 0 | 0 | 9,690 |
935,378 | 2009-06-01T15:42:00.000 | 0 | 0 | 1 | 0 | python,methods | 935,431 | 7 | false | 0 | 0 | Some methods with a double underscore prefix and suffix are special. For example, __init__ is called whenever an instance of that class is created, and __str__ is called when the object is to be printed. Basically, they can be called in special ways. You can use them like any other method, or you can invoke them through the special way associated to them.
I don't know about double-underscore global functions (not belonging to any class), but I think there aren't any. | 4 | 38 | 0 | What is the difference between __method__, method and _method__?
Is there any or for some random reason people thought that __doc__ should be right like that instead of doc. What makes a method more special than the other? | Difference between "__method__" and "method" | 0 | 0 | 0 | 9,690 |
935,378 | 2009-06-01T15:42:00.000 | 23 | 0 | 1 | 0 | python,methods | 936,012 | 7 | false | 0 | 0 | method is just a normal method
_method should not be called unless you know what you are doing, which normally means that you have written the method yourself.
__method the 2 underscores are used to prevent name mangeling. Attributes or methods like this are accessible over instance._ClassName__method. Although a lot of people call this "private" it is not. You should never use this to prevent someone from accessing this method, use _method instead.
__method__ is used for special methods which modify the behavior of the instance. Do not name your own methods like this. | 4 | 38 | 0 | What is the difference between __method__, method and _method__?
Is there any or for some random reason people thought that __doc__ should be right like that instead of doc. What makes a method more special than the other? | Difference between "__method__" and "method" | 1 | 0 | 0 | 9,690 |
935,378 | 2009-06-01T15:42:00.000 | 0 | 0 | 1 | 0 | python,methods | 935,399 | 7 | false | 0 | 0 | Methods prefaced and prefixed with the double underscore are generally so marked to indicate that they are part of the Python language specification. | 4 | 38 | 0 | What is the difference between __method__, method and _method__?
Is there any or for some random reason people thought that __doc__ should be right like that instead of doc. What makes a method more special than the other? | Difference between "__method__" and "method" | 0 | 0 | 0 | 9,690 |
936,381 | 2009-06-01T19:36:00.000 | 1 | 0 | 0 | 0 | python,xml,oracle,xmltype | 946,854 | 3 | true | 0 | 0 | I managed to do this with cx_Oracle.
I used the sys.xmltype.createxml() function in the statement that inserts the rows in a table with XMLTYPE fields; then I used prepare() and setinputsizes() to specify that the bind variables I used for XMLTYPE fields were of cx_Oracle.CLOB type. | 1 | 5 | 0 | It seems cx_Oracle doesn't.
Any other suggestion for handling xml with Oracle and Python is appreciated.
Thanks. | Is there an Oracle wrapper for Python that supports xmltype columns? | 1.2 | 1 | 0 | 1,256 |
936,783 | 2009-06-01T21:06:00.000 | 1 | 1 | 0 | 1 | python,ssh | 936,816 | 2 | false | 0 | 0 | Well, the main reason probably was that when people started getting interested in such things in VHLLs such as Python, it didn't make sense to them to implement a standard which they themselves would not find useful.
I am not familiar with the protocol differences, but would it be possible for you to adapt an existing codebase to the older protocol? | 2 | 4 | 0 | There seem to be a few good pure Python SSH2 client implementations out there, but I haven't been able to find one for SSH1. Is there some specific reason for this other than lack of interest in such a project? I am fully aware of the many SSH1 vulnerabilities, but a pure Python SSH1 client implementation would still be very useful to those of us who want to write SSH clients to manage older embedded devices which only support SSH1 (Cisco PIX for example). I also know I'm not the only person looking for this.
The reason I'm asking is because I'm bored, and I've been thinking about taking a stab at writing this myself. I've just been hesitant to start, since I know there are a lot of people out there who are much smarter than me, and I figured there might be some reason why nobody has done it yet. | Why no pure Python SSH1 (version 1) client implementations? | 0.099668 | 0 | 0 | 1,865 |
936,783 | 2009-06-01T21:06:00.000 | 3 | 1 | 0 | 1 | python,ssh | 940,483 | 2 | true | 0 | 0 | SSHv1 was considered deprecated in 2001, so I assume nobody really wanted to put the effort into it. I'm not sure if there's even an rfc for SSH1, so getting the full protocol spec may require reading through old source code.
Since there are known vulnerabilities, it's not much better than telnet, which is almost universally supported on old and/or embedded devices. | 2 | 4 | 0 | There seem to be a few good pure Python SSH2 client implementations out there, but I haven't been able to find one for SSH1. Is there some specific reason for this other than lack of interest in such a project? I am fully aware of the many SSH1 vulnerabilities, but a pure Python SSH1 client implementation would still be very useful to those of us who want to write SSH clients to manage older embedded devices which only support SSH1 (Cisco PIX for example). I also know I'm not the only person looking for this.
The reason I'm asking is because I'm bored, and I've been thinking about taking a stab at writing this myself. I've just been hesitant to start, since I know there are a lot of people out there who are much smarter than me, and I figured there might be some reason why nobody has done it yet. | Why no pure Python SSH1 (version 1) client implementations? | 1.2 | 0 | 0 | 1,865 |
939,746 | 2009-06-02T14:02:00.000 | 0 | 0 | 0 | 0 | python | 947,222 | 2 | false | 0 | 0 | To the best of my knowledge, python does not contain the ability to simulate keystrokes. You can however use python to call a program which has the functionality that you need for OS X. You could also write said program using Objective C most likely.
Or you could save yourself the pain and use Automator. Perhaps if you posted more details about what you were automating, I could add something further. | 1 | 1 | 0 | I am trying to automate a app using python. I need help to send keyboard commands through python. I am using powerBook G4. | How i can send the commands from keyboards using python. I am trying to automate mac app (GUI) | 0 | 0 | 1 | 665 |
939,754 | 2009-06-02T14:03:00.000 | 19 | 0 | 1 | 0 | python,multithreading | 939,827 | 6 | false | 0 | 0 | You have to consider multiple things if you want to use multiple threads:
You can only run #processors threads simultaneously. (Obvious)
In Python each thread is a 'kernel thread' which normally takes a non-trivial amount of resources (8 mb stack by default on linux)
Python has a global interpreter lock, which means only one python instructions can be processed at once independently of the number of processors. This lock is however released if one of your threads waits on IO.
The conclusion I take from that:
If you are doing IO (Turbogears, Twisted) or are using properly coded extension modules (numpy) use threads.
If you want to execute python code concurrently use processes (easiest with multiprocess module) | 3 | 6 | 0 | I'm new to threading and was wondering if it's bad to spawn a lot of threads for various tasks (in a server environment). Do threads take up a lot more memory/cpu compared to more linear programming? | Threading In Python | 1 | 0 | 0 | 3,257 |
939,754 | 2009-06-02T14:03:00.000 | 4 | 0 | 1 | 0 | python,multithreading | 939,815 | 6 | false | 0 | 0 | It depends on the platform.
Windows threads have to commit around 1MB of memory when created. It's better to have some kind of threadpool than spawning threads like a madman, to make sure you never allocate more than a fixed amount of threads. Also, when you work in Python, you're subject to the Global Interpreter Lock which hinders code that rely on lots of concurrent threads.
On Unix, you may consider using different processes instead of threads, or look at other asynchronous way of doing things (the Twisted server framework has interesting ways of handling asynchronous network tasks, and if you feel really adventurous you can take a look at stackless Python, a continuation framework which don't really use kernel threads at all). | 3 | 6 | 0 | I'm new to threading and was wondering if it's bad to spawn a lot of threads for various tasks (in a server environment). Do threads take up a lot more memory/cpu compared to more linear programming? | Threading In Python | 0.132549 | 0 | 0 | 3,257 |
939,754 | 2009-06-02T14:03:00.000 | 5 | 0 | 1 | 0 | python,multithreading | 941,253 | 6 | false | 0 | 0 | Since you're new to threading, there's something else worth bearing in mind - which I prefer to view as parallel scoping of values.
With traditional linear/sequential programming for any given object you only have one thread accessing and changing a piece of data. This is generally made safe due to having lexical scope. Specifically one function can operate on a variable's value without affect a global value. If you don't have lexical scope, or poor lexical scoping, then changing the value of a variable named "foo" in one function affects another called "foo". It's less commonly a problem these days, but still common enough to be alluding to.
With threading, you have the same issue, in more subtle ways. Whilst you still have lexical scoping helping you - in that a local value "X" inside one function is independent of another local value called "X" in another, the fact that data structures are mutable is a major source of bugs in threading.
Specifically, if a function is passed a mutable value, then in a threaded environment unless you have taken care, that function cannot guarantee that the value is not being changed by anything else.
This shared state is the source of probably 90-99% of bugs in threaded systems, and can be very hard to debug. As a result, if you're going to write a threaded system you should try to bear in mind the distance that your shared values will travel - ie the scope of parallel access.
In order to limit bugs you have a handful of options which are known to work:
Use no shared state - pass shared data using thread safe queues
Place locks around all shared data, and ensure this is used religiously throughout your code. This can be far harder sometimes than people think. The problem comes from when you "forget" to lock an object - something which is remarkably easy for people to do.
Have a single object - an owner - in charge of shared state. Allow client threads to ask it for copies of values in the shared state, which are accompanied by a token. When they want to update the shared state, they pass back messages to the single object, along with the token they had. The owner can then determine whether an update clash has occured.
1 is most equivalent to unix pipelines. 3 is logically equivalent to version control, and is normally referred to as software transactional memory.
1 & 3 are modes of concurrency supported in Kamaelia which aims to eliminate bugs caused by class 2. (disclosure, I run the Kamaelia project) 2 isn't supported because it relies on "always getting everything right".
No matter which approach you use to solve your problem though, bearing in mind this issue, and the ways of dealing with it, and planning upfront how you intend to deal with it will save you no end of headaches later on. | 3 | 6 | 0 | I'm new to threading and was wondering if it's bad to spawn a lot of threads for various tasks (in a server environment). Do threads take up a lot more memory/cpu compared to more linear programming? | Threading In Python | 0.16514 | 0 | 0 | 3,257 |
940,149 | 2009-06-02T15:15:00.000 | 0 | 0 | 0 | 0 | python,ruby,user-interface,desktop,software-distribution | 976,069 | 7 | false | 0 | 1 | I don't think anyone really answered his question.
As for me, I use VB to do Shell() calls to Ocra compiled Ruby scripts.
It works pretty well and allows me to create apps that run in all modern OS.
Linux testing is done by using Wine to run and ensuring that I use a pre .NET version of VB for the .exe compilation. | 3 | 10 | 0 | Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?
I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.
RubyGTK, wxRuby, etc seem to be promising, but they do not solve the issue of distributing an app in a way that doesn't require Ruby pre-installed on users' computers — and libraries like ruby2exe seem to be horribly out-of-date and incomplete.
Generally — what is the current fad?
BTW: if there is a really easy solution to this in Python, I may consider redoing the stuff I'm up to in Python. | Distributing Ruby/Python desktop apps | 0 | 0 | 0 | 3,071 |
940,149 | 2009-06-02T15:15:00.000 | 2 | 0 | 0 | 0 | python,ruby,user-interface,desktop,software-distribution | 940,214 | 7 | false | 0 | 1 | The state of affairs is pretty bad. The most reliable method at present is probably to use JRuby. I know that's probably not the answer you want to hear, but, as you say, ruby2exe is unreliable, and Shoes is a long way off (and isn't even intended to be a full-scale application). Personally, I dislike forcing users to install GTK or Qt or wxWidgets, but the JVM is fairly ubiquitous. | 3 | 10 | 0 | Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?
I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.
RubyGTK, wxRuby, etc seem to be promising, but they do not solve the issue of distributing an app in a way that doesn't require Ruby pre-installed on users' computers — and libraries like ruby2exe seem to be horribly out-of-date and incomplete.
Generally — what is the current fad?
BTW: if there is a really easy solution to this in Python, I may consider redoing the stuff I'm up to in Python. | Distributing Ruby/Python desktop apps | 0.057081 | 0 | 0 | 3,071 |
940,149 | 2009-06-02T15:15:00.000 | -2 | 0 | 0 | 0 | python,ruby,user-interface,desktop,software-distribution | 942,712 | 7 | false | 0 | 1 | I've read about (but not used) Seattlerb's Wilson, which describes itself as a pure x86 assembler, but it doesn't sound like it'd be cross-platform or GUI. | 3 | 10 | 0 | Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?
I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.
RubyGTK, wxRuby, etc seem to be promising, but they do not solve the issue of distributing an app in a way that doesn't require Ruby pre-installed on users' computers — and libraries like ruby2exe seem to be horribly out-of-date and incomplete.
Generally — what is the current fad?
BTW: if there is a really easy solution to this in Python, I may consider redoing the stuff I'm up to in Python. | Distributing Ruby/Python desktop apps | -0.057081 | 0 | 0 | 3,071 |
940,564 | 2009-06-02T16:39:00.000 | 0 | 0 | 0 | 0 | java,python,spring | 10,500,205 | 3 | false | 1 | 0 | Good stuff. I have used Spring Java, Spring Dot Net and now starting with Spring Python. Python has always been pretty easy to use for programmers; I think, especially since it's easy to write. I found Spring Dot Net to be a bit confusing, but both Spring Java and Python seem to be similar. I'm sure they have their differences, but so far at least I'm not all so confused with the Python implementation of Spring. | 1 | 18 | 0 | I am an avid fan of the Spring framework for Java (by Rod Johnson).
I am learning Python and was excited to find about Spring for Python.
I would be interested in hearing the community's views on the comparison of
these two flavours of Spring. How well does it fit Python's paradigms etc. | How does Spring for Python compare with Spring for Java | 0 | 0 | 0 | 16,197 |
941,638 | 2009-06-02T20:11:00.000 | 0 | 0 | 0 | 0 | javascript,python,html,web-applications | 943,612 | 4 | false | 1 | 0 | set "Indexes" option to the directory in the apache config.
To learn how to build webapps in python, learn django. | 2 | 2 | 0 | Goal: simple browser app, for navigating files on a web server, in a tree view.
Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.)
What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. Learn them? Grab a JS example from the web and rework? Can such a thing be built in raw HTML? Python I'm advanced beginner but I realize that's server side.
If you were going to build such a toy from scratch, what would you use? What would be the totally easy, cheesy way, the intermediate way, the fully professional way?
No Django yet please -- This is an exercise in learning web programming nuts and bolts. | How to construct a web file browser? | 0 | 0 | 1 | 552 |
941,638 | 2009-06-02T20:11:00.000 | 1 | 0 | 0 | 0 | javascript,python,html,web-applications | 941,664 | 4 | false | 1 | 0 | If you want to make interactive browser, you have to learn JS and ajax.
If you want to build only browser based on links, python would be enough. | 2 | 2 | 0 | Goal: simple browser app, for navigating files on a web server, in a tree view.
Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.)
What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. Learn them? Grab a JS example from the web and rework? Can such a thing be built in raw HTML? Python I'm advanced beginner but I realize that's server side.
If you were going to build such a toy from scratch, what would you use? What would be the totally easy, cheesy way, the intermediate way, the fully professional way?
No Django yet please -- This is an exercise in learning web programming nuts and bolts. | How to construct a web file browser? | 0.049958 | 0 | 1 | 552 |
942,730 | 2009-06-03T01:46:00.000 | 1 | 0 | 0 | 0 | python,user-interface,mouse,cursor,pythoncard | 942,839 | 1 | true | 0 | 0 | PythonCard builds on top of wx, so if you import wx you should be able to build a suitable cursor (e.g. with wx.CursorFromImage), set it (e.g. with wx.BeginBusyCursor) when your wait begins, and end it (with wx.EndBusyCursor) when your wait ends. | 1 | 0 | 0 | How do I change the mouse cursor to indicate a waiting state using Python and PythonCard?
I didn't see anything in the documentation. | How to Change Mouse Cursor in PythonCard | 1.2 | 0 | 0 | 591 |
944,700 | 2009-06-03T13:19:00.000 | 241 | 0 | 1 | 0 | python,math | 944,756 | 18 | false | 0 | 0 | numpy.isnan(number) tells you if it's NaN or not. | 1 | 1,412 | 0 | float('nan') represents NaN (not a number). But how do I check for it? | How can I check for NaN values? | 1 | 0 | 0 | 2,218,724 |
945,001 | 2009-06-03T14:12:00.000 | 0 | 0 | 0 | 0 | python,django,rss | 1,095,528 | 3 | true | 1 | 0 | I've been banging my head against this one for a while. It seems that the django rss system need a "datetime" object instead of just the date (since it wants a time zone, and the date object doesn't have a time, let alone a time zone...)
I might be wrong though, but it's something that I've found via the error logs. | 1 | 0 | 0 | I'm publishing a feed from a Django application.
I subclassed django.contrib.syndication.feeds.Feed, everything works fine, except the date that doesn't get published on the feed.
Here's the method I've created on my Feed class
def item_pubdate(self, item):
return item.date
this method never gets called.... | Publish feeds using Django | 1.2 | 0 | 0 | 619 |
947,436 | 2009-06-03T21:43:00.000 | 6 | 0 | 0 | 0 | python,django | 947,486 | 1 | false | 1 | 0 | Simple: Don't use global objects.
If you want an object inside the view, instantiate it inside the view, not as global. That way it will be collected after the view ends. | 1 | 0 | 0 | Here is my problem. DJango continues to store all the global objects after the first run of a script. For instance, an object you instantiate in views.py globally will be there until you restart the app server. This is fine unless your object is tied to some outside resource that may time out. Now the way I was thinking to correct was some sort of factory method that checks if the object is instantiated and creates it if it's not, and then returns it. However, the this fails because the object exists there since the last page request, so a factory method is always returning the object that was instantiated during the first request.
What I am looking for is a way to trigger something to happen on a per request basis. I have seen ways of doing this by implementing your own middleware, but I think that is overkill. Does anyone know of some reserved methods or some other per request trigger. | How to I reload global vars on every page refresh in DJango | 1 | 0 | 0 | 371 |
947,810 | 2009-06-03T23:21:00.000 | 0 | 0 | 1 | 0 | python,shell,read-eval-print-loop,interactive-session | 38,593,747 | 20 | false | 0 | 0 | Some comments were asking how to save all of the IPython inputs at once. For %save magic in IPython, you can save all of the commands programmatically as shown below, to avoid the prompt message and also to avoid specifying the input numbers.
currentLine = len(In)-1
%save -f my_session 1-$currentLine
The -f option is used for forcing file replacement and the len(IN)-1 shows the current input prompt in IPython, allowing you to save the whole session programmatically. | 3 | 451 | 0 | I find myself frequently using Python's interpreter to work with databases, files, etc -- basically a lot of manual formatting of semi-structured data. I don't properly save and clean up the useful bits as often as I would like. Is there a way to save my input into the shell (db connections, variable assignments, little for loops and bits of logic) -- some history of the interactive session? If I use something like script I get too much stdout noise. I don't really need to pickle all the objects -- though if there is a solution that does that, it would be OK. Ideally I would just be left with a script that ran as the one I created interactively, and I could just delete the bits I didn't need. Is there a package that does this, or a DIY approach? | How to save a Python interactive session? | 0 | 0 | 0 | 215,023 |
947,810 | 2009-06-03T23:21:00.000 | 0 | 0 | 1 | 0 | python,shell,read-eval-print-loop,interactive-session | 44,425,033 | 20 | false | 0 | 0 | I'd like to suggest another way to maintain python session through tmux on linux. you run tmux, attach your self to the session you opened (if not attached after opening it directly). execute python and do whatever you are doing on it. then detach from session. detaching from a tmux session does not close the session. the session remains open.
pros of this method:
you can attach to this session from any other device (in case you can ssh your pc)
cons of this method:
this method does not relinquish the resources used by the opened python session until you actually exist the python interpreter. | 3 | 451 | 0 | I find myself frequently using Python's interpreter to work with databases, files, etc -- basically a lot of manual formatting of semi-structured data. I don't properly save and clean up the useful bits as often as I would like. Is there a way to save my input into the shell (db connections, variable assignments, little for loops and bits of logic) -- some history of the interactive session? If I use something like script I get too much stdout noise. I don't really need to pickle all the objects -- though if there is a solution that does that, it would be OK. Ideally I would just be left with a script that ran as the one I created interactively, and I could just delete the bits I didn't need. Is there a package that does this, or a DIY approach? | How to save a Python interactive session? | 0 | 0 | 0 | 215,023 |
947,810 | 2009-06-03T23:21:00.000 | 0 | 0 | 1 | 0 | python,shell,read-eval-print-loop,interactive-session | 54,548,764 | 20 | false | 0 | 0 | To save input and output on XUbuntu:
In XWindows, run iPython from the Xfce terminal app
click Terminal in the top menu bar and look for save contents in the dropdown
I find this saves the input and output, going all the way back to when I opened the terminal. This is not ipython specific, and would work with ssh sessions or other tasks run from the terminal window. | 3 | 451 | 0 | I find myself frequently using Python's interpreter to work with databases, files, etc -- basically a lot of manual formatting of semi-structured data. I don't properly save and clean up the useful bits as often as I would like. Is there a way to save my input into the shell (db connections, variable assignments, little for loops and bits of logic) -- some history of the interactive session? If I use something like script I get too much stdout noise. I don't really need to pickle all the objects -- though if there is a solution that does that, it would be OK. Ideally I would just be left with a script that ran as the one I created interactively, and I could just delete the bits I didn't need. Is there a package that does this, or a DIY approach? | How to save a Python interactive session? | 0 | 0 | 0 | 215,023 |
948,212 | 2009-06-04T01:40:00.000 | 3 | 0 | 0 | 0 | python,sql,sqlalchemy | 951,640 | 4 | true | 0 | 0 | Well, thanks to Hao Lian above, I came up with a functional if painful solution.
Assume that we have a declarative-style mapped class, Clazz, and a list of tuples of compound primary key values, values
(Edited to use a better (IMO) sql generation style):
from sqlalchemy.sql.expression import text,bindparam
...
def __gParams(self, f, vs, ts, bs):
for j,v in enumerate(vs):
key = f % (j+97)
bs.append(bindparam(key, value=v, type_=ts[j]))
yield ':%s' % key
def __gRows(self, ts, values, bs):
for i,vs in enumerate(values):
f = '%%c%d' % i
yield '(%s)' % ', '.join(self.__gParams(f, vs, ts, bs))
def __gKeys(self, k, ts):
for c in k:
ts.append(c.type)
yield str(c)
def __makeSql(self,Clazz, values):
t = []
b = []
return text(
'(%s) in (%s)' % (
', '.join(self.__gKeys(Clazz.__table__.primary_key,t)),
', '.join(self.__gRows(t,values,b))),
bindparams=b)
This solution works for compound or simple primary keys. It's probably marginally slower than the col.in_(keys) for simple primary keys though.
I'm still interested in suggestions of better ways to do this, but this way is working for now and performs noticeably better than the or_(and_(conditions)) way, or the for key in keys: do_stuff(q.get(key)) way. | 1 | 10 | 0 | I'm trying to find a way to cause SQLAlchemy to generate a query of the following form:
select * from t where (a,b) in ((a1,b1),(a2,b2));
Is this possible?
If not, any suggestions on a way to emulate it? | Sqlalchemy complex in_ clause with tuple in list of tuples | 1.2 | 1 | 0 | 6,490 |
948,493 | 2009-06-04T03:42:00.000 | 0 | 0 | 0 | 0 | python,django,validation | 948,500 | 3 | false | 1 | 0 | Well, you can always use a GUID. As you said it would be stored as a valid key. | 1 | 2 | 0 | I'm using django for a web-magazine with subscriber-content. when a user purchases a subscription, the site will create a validation key, and send it to the user email address.
The validation key would be added to a list of "valid keys" until it is used.
What is the best method for creating a simple yet unique key? Can someone suggest a standard python library for key-creation/validation/ect?
This might be a very simple question, but I'm very new. ;) | method for creating a unique validation key/number | 0 | 0 | 0 | 1,123 |
949,784 | 2009-06-04T10:42:00.000 | 3 | 0 | 1 | 0 | python,read-eval-print-loop | 949,847 | 3 | false | 0 | 0 | You either need to go non-blocking or use a thread.
I would personally use Twisted for concurrency, which also offers a REPL-protocol which is easy to integrate. | 1 | 5 | 0 | I am currently developing a simple application in python that connects to a server. At the moment, it's single-threaded (as multithreading is not currently required).
However I would like - for debugging, maintenance and such to also be able to have a REPL via stdin.
How do I go about that, if possible? Will I need to keep anything in mind? Will I have to make a separate thread for it? | Python REPL for a running process | 0.197375 | 0 | 0 | 1,975 |
950,145 | 2009-06-04T12:13:00.000 | 2 | 0 | 0 | 0 | python,3d,wxpython,embedding,blender | 950,196 | 5 | false | 0 | 1 | Blender has python plugins, you can write a plugin to interract with your program. | 1 | 1 | 0 | Is it possible to embed a 3-D editor inside my wxPython application? (I'm thinking Blender, but other suggestions are welcome.)
My application opens a wxPython window, and I want to have a 3-D editor inside of it. Of course, I want my program and the 3-D editor to interact with each other.
Possible? How? | Embedding a 3-D editor (such as Blender) in a wxPython application | 0.07983 | 0 | 0 | 1,823 |
950,790 | 2009-06-04T14:03:00.000 | 4 | 0 | 0 | 0 | python,django | 950,874 | 2 | false | 1 | 0 | Yes, you can use the same database.
Some people use Django on top of a PHP application for its admin functionality, or to build newer features with Django and its ORM.
What I'm trying to say is that if you're putting data from your crawl into the same place that you will let Django store its data, you can access them as long as you create Django models for each table.
However, I don't see why the crawler can't be written within Django itself. I've written some non web based apps (a crawler and an aggregator) in Django and it works quite well. | 1 | 1 | 0 | I'm planning on writing a web crawler and a web-based front end for it (or, at least, the information it finds). I was wondering if it's possible to use the Django framework to let the web crawler use the same MySQL backend as the website (without making the web crawler a "website" in it's self). | Use Django Framework with Website and Stand-alone App | 0.379949 | 0 | 0 | 1,344 |
951,974 | 2009-06-04T17:29:00.000 | 0 | 0 | 0 | 0 | python,ide,komodo | 952,842 | 5 | false | 0 | 1 | try using eclipse instead with PyDev. | 2 | 3 | 0 | Continuing on with my Python learning, I just installed Komodo edit, are there any recommended add ins/extensions that I should include? Any recommendations on using it or another GUI designer (TkInter base)? | Komodo Extension | 0 | 0 | 0 | 1,483 |
951,974 | 2009-06-04T17:29:00.000 | 0 | 0 | 0 | 0 | python,ide,komodo | 7,241,975 | 5 | false | 0 | 1 | I use to install MoreKomodo and TweakUI after putting Komodo on some machine for me. | 2 | 3 | 0 | Continuing on with my Python learning, I just installed Komodo edit, are there any recommended add ins/extensions that I should include? Any recommendations on using it or another GUI designer (TkInter base)? | Komodo Extension | 0 | 0 | 0 | 1,483 |
952,110 | 2009-06-04T17:51:00.000 | 2 | 0 | 1 | 0 | python,recursion,palindrome | 952,171 | 11 | false | 0 | 0 | Here's another viewpoint
A palindromic string is
Some letter, x.
Some palindromic substrinng.
The same letter, x, repeated.
Also, note that you may be given a proper English sentence "Able was I ere I saw Elba." with punctuation. Your palindrome checker may have to quietly skip punctuation. Also, you may have to quietly match without considering case. This is slightly more complex.
Some leading punctuation. Some letter, x.
Some palindromic substring.
Some letter, x, repeated without regard to case. Some trailing punctuation.
And, by definition, a zero-length string is a palindrome. Also a single-letter string (after removing punctuation) is a palindrome. | 2 | 10 | 0 | I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done . Im using Python. | Recursive Function palindrome in Python | 0.036348 | 0 | 0 | 99,261 |
952,110 | 2009-06-04T17:51:00.000 | 3 | 0 | 1 | 0 | python,recursion,palindrome | 952,129 | 11 | false | 0 | 0 | If a string is zero or one letters long, it's a palindrome.
If a string has the first and last letters the same, and the remaining letters (I think it's a [1: -1] slice in Python, but my Python is a bit rusty) are a palindrome, it's a palindrome.
Now, write that as a palindrome function that takes a string. It will call itself. | 2 | 10 | 0 | I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done . Im using Python. | Recursive Function palindrome in Python | 0.054491 | 0 | 0 | 99,261 |
952,648 | 2009-06-04T19:34:00.000 | 1 | 0 | 1 | 0 | python,ruby,debugging,parser-generator | 2,475,183 | 5 | false | 0 | 0 | ANTLR above has the advantage to generate human readable and understandable code,
since it is (a very sophisticated and powerful) top-down parser,
so you can step through it with a regular debugger
and see what it really is doing.
That's why it is my parser generator of choice.
Bottom up parser generators like PLY have the disadvantage
that for larger grammars it is almost impossible to understand
what the debugging output really means and why the
parsing table is like it is. | 1 | 4 | 0 | The first parser generator I've worked with was Parse::RecDescent, and the guides/tutorials available for it were great, but the most useful feature it has was it's debugging tools, specifically the tracing capabilities ( activated by setting $RD_TRACE to 1 ). I am looking for a parser generator that can help you debug it's rules.
The thing is, it has to be written in python or in ruby, and have a verbose mode/trace mode or very helpful debugging techniques.
Does anyone know such a parser generator ?
EDIT: when I said debugging, I wasn't referring to debugging python or ruby. I was referring to debugging the parser generator, see what it's doing at every step, see every char it's reading, rules it's trying to match. Hope you get the point.
BOUNTY EDIT: to win the bounty, please show a parser generator framework, and illustrate some of it's debugging features. I repeat, I'm not interested in pdb, but in parser's debugging framework. Also, please don't mention treetop. I'm not interested in it. | Help me find an appropriate ruby/python parser generator | 0.039979 | 0 | 0 | 2,569 |
953,701 | 2009-06-05T00:01:00.000 | 9 | 1 | 0 | 0 | python,gps,gpsd | 973,022 | 6 | true | 0 | 0 | Apparently the python module that comes with gpsd is the best module to go with for us.
The gps module coming with the gpsd has some very useful functions. The first one is getting the data from gpsd and transforming those data in a usable data structure.
Then the moduls give you access to your speed, and your current heading relative to north.
Also included is a function for calculating the distance between two coordinates on the earth taking the spherical nature of earth into account.
The functions that are missing for our special case are:
Calculating the heading between to points. Means I am at point a facing north to which degree do I have to turn to face the point I want to navigate to.
Taking the data of the first function and our current heading to calculate a turn in degrees that we have to do to face a desired point (not a big deal because it is mostly only a subtraction)
The biggest problem for working with this library is that it is mostly a wrapper for the gpsd so if you are programming on a different OS then you gpscode should work on like Windows or MacOS you are not able to run the code or to install the module. | 1 | 8 | 0 | I'm looking for a free library for python that can calculate your direction and your speed from GPS coordinates and maybe can calculate if you are in some boundaries or things like this.
Are there Libraries that you know and that worked well for you?
We are using python on a linux machine and getting the data from the gpsd. So I hope there is no need for a speciel library for only talking to the device. What I'm looking for is python code doing some basic calculations with the data. Such as comparing the last positions and calculate speed and direction. | Which gps library would you recommend for python? | 1.2 | 0 | 0 | 32,709 |
955,941 | 2009-06-05T13:47:00.000 | 3 | 0 | 1 | 0 | python | 955,956 | 7 | false | 0 | 0 | os.path.isdir('string')
os.path.isfile('string') | 2 | 152 | 0 | How do you check whether a file is a normal file or a directory using python? | How to identify whether a file is normal file or directory | 0.085505 | 0 | 0 | 25,290 |
955,941 | 2009-06-05T13:47:00.000 | 42 | 0 | 1 | 0 | python | 956,092 | 7 | false | 0 | 0 | As other answers have said, os.path.isdir() and os.path.isfile() are what you want. However, you need to keep in mind that these are not the only two cases. Use os.path.islink() for symlinks for instance. Furthermore, these all return False if the file does not exist, so you'll probably want to check with os.path.exists() as well. | 2 | 152 | 0 | How do you check whether a file is a normal file or a directory using python? | How to identify whether a file is normal file or directory | 1 | 0 | 0 | 25,290 |
956,904 | 2009-06-05T16:39:00.000 | 0 | 0 | 0 | 1 | python,django,amazon-s3,amazon-ec2 | 6,308,720 | 5 | false | 1 | 0 | I'd suggest using a separately-mounted EBS volume. I tried doing the same thing for some movie files. Access to S3 was slow, and S3 has some limitations like not being able to rename files, no real directory structure, etc.
You can set up EBS volumes in a RAID5 configuration and add space as you need it. | 1 | 4 | 0 | I have a webapp (call it myapp.com) that allows users to upload files. The webapp will be deployed on Amazon EC2 instance. I would like to serve these files back out to the webapp consumers via an s3 bucket based domain (i.e. uploads.myapp.com).
When the user uploads the files, I can easily drop them in into a folder called "site_uploads" on the local ec2 instance. However, since my ec2 instance has finite storage, with a lot of uploads, the ec2 file system will fill up quickly.
It would be great if the ec2 instance could mount and s3 bucket as the "site_upload" directory. So that uploads to the EC2 "site_upload" directory automatically end up on uploads.myapp.com (and my webapp can use template tags to make sure the links for this uploaded content is based on that s3 backed domain). This also gives me scalable file serving, as request for files hits s3 and not my ec2 instance. Also, it makes it easy for my webapp to perform scaling/resizing of the images that appear locally in "site_upload" but are actually on s3.
I'm looking at s3fs, but judging from the comments, it doesn't look like a fully baked solution. I'm looking for a non-commercial solution.
FYI, The webapp is written in django, not that that changes the particulars too much. | mounting an s3 bucket in ec2 and using transparently as a mnt point | 0 | 1 | 0 | 8,589 |
958,491 | 2009-06-05T22:51:00.000 | 1 | 0 | 0 | 0 | python,keyboard | 981,709 | 2 | false | 0 | 1 | I think it's going to depend heavily on the environment: curses & the activestate recipe are good for command line, but if you want it to run in a DE, you'll need some hooks to that DE. You might look at Qt or GTK bindings for python, or there's a python-xlib library that might let you tie right into the X system.
So I guess the answer is "it depends." Are you looking for console noecho functionality, or a text replacement program for a DE, or an xmodmap-style layout changer? | 2 | 5 | 0 | I'm writing a macro generator/ keyboard remapper in python, for xubuntu.
I've figured out how to intercept and record keystrokes, and send keystrokes I want to record, but I haven't figured out how to block keystrokes. I need to disable keyboard input to remap a key. For example, if I wanted to send 'a' when I press the 's' key, I can currently record the 'a' keystroke, and set it to playback when I press the 's' key. I cannot, however keep the 's' keystroke from being sent alongside it.
I used the pyxhook module from an open source keyboard-logger for the hooks, and a again, the xtest fake input method from the python x library.
I remember reading somewhere about somebody blocking all keyboard input by redirecting all keystrokes to an invisible window by using tkinter. If somebody could post that method that'd be great.
I need something that will block all keystrokes, but not turn off my keyboard hooks. | Python disable/redirect keyboard input | 0.099668 | 0 | 0 | 5,147 |
958,491 | 2009-06-05T22:51:00.000 | 0 | 0 | 0 | 0 | python,keyboard | 993,251 | 2 | false | 0 | 1 | I've got a keyboard hook that detects X events. I'm looking for a way to globally prevent a single keyboard event from being sent to a window. Something that works by accessing the event queue and removing the keyboard event from it would be ideal. It looks like it should be possible using Python Xlib, but I can't figure it out. | 2 | 5 | 0 | I'm writing a macro generator/ keyboard remapper in python, for xubuntu.
I've figured out how to intercept and record keystrokes, and send keystrokes I want to record, but I haven't figured out how to block keystrokes. I need to disable keyboard input to remap a key. For example, if I wanted to send 'a' when I press the 's' key, I can currently record the 'a' keystroke, and set it to playback when I press the 's' key. I cannot, however keep the 's' keystroke from being sent alongside it.
I used the pyxhook module from an open source keyboard-logger for the hooks, and a again, the xtest fake input method from the python x library.
I remember reading somewhere about somebody blocking all keyboard input by redirecting all keystrokes to an invisible window by using tkinter. If somebody could post that method that'd be great.
I need something that will block all keystrokes, but not turn off my keyboard hooks. | Python disable/redirect keyboard input | 0 | 0 | 0 | 5,147 |
959,479 | 2009-06-06T11:08:00.000 | 3 | 0 | 1 | 0 | python,windows,development-environment | 959,494 | 10 | false | 0 | 0 | Well, if you're thinking of setting up an Ubuntu VM anyway, you might as well make that your development environment. Then you can install Apache and MySQL or Postgres on that VM just via the standard packaging tools (apt-get install), and there's no danger of polluting your Windows environment.
You can either do the actual development on your Windows machine via your favourite IDE, using the VM as a networked drive and saving the code there, or you can just use the VM as a full desktop environment and do everything there, which is what I would recommend. | 3 | 9 | 0 | I currently work with .NET exclusively and would like to have a go at python. To this end I need to set up a python development environment. I guide to this would be handy. I guess I would be doing web development so will need a web server and probably a database. I also need pointers to popular ORM's, an MVC framework, and a testing library.
One of my main criteria with all this is that I want to understand how it works, and I want it to be as isolated as possible. This is important as i am wary of polluting what is a working .NET environment with 3rd party web and database servers. I am perfectly happy using SQLite to start with if this is possible.
If I get on well with this I am also likely to want to set up automated build and ci server (On a virtual machine, probably ubuntu). Any suggestions for these would be useful.
My ultimate aim if i like python is to have similar sorts of tools that i have available with .NET and to really understand the build and deployment of it all. To start with I will settle for a simple development environment that is as isolated as possible and will be easy to remove if I don't like it. I don't want to use IronPython as I want the full experience of developing a python solution using the tools and frameworks that are generally used. | I need a beginners guide to setting up windows for python development | 0.059928 | 0 | 0 | 1,647 |
959,479 | 2009-06-06T11:08:00.000 | 1 | 0 | 1 | 0 | python,windows,development-environment | 986,203 | 10 | false | 0 | 0 | NOTE: I included a lot of links to frameworks, projects and what-not, but as a new user I was limited to 1 link per answer. If someone else with enough reputation to edit wants/can edit them into this answer instead of the footnotes, I'd be grateful.
There are some Python IDE's such as Wing IDE[1], I believe some people use Eclipse[2] with a python plugin[3] as well. A lot of people in the #python channel of FreeNode seem to prefer vim, emacs, nano and similar text editors in favor of IDE's. My personal preffered editor is Vim, but if you've mostly done .NET development on windows, presumably with the usual Visual X IDE's, vim and emacs will probably cause you culture shock and you'd be better of using an IDE.
Nearly all python web frameworks* support the WSGI standard[4], most of the large web servers have some sort of plugin to support WSGI, the others support WSGI via fast cgi or plain cgi.
The Zope[5] and Django[6] frameworks have their own ORM's, of other ORM's the two most well known appear to be SQL Alchemy[7] and SQL Object[8]. I only have experience with the former, but both support all possible sane database choices, including SQLite which is installed together with Python and hence perfectly suited to testing and experimenting without polluting your .NET environment with 3rd part web servers and database servers.
The builtin unittest[9] and pyunit[10] frameworks seem to be the preffered solutions for unit testing, but I don't have much experience with these.
bpython[11] and ipython[12] offer enhanced interactive python shells which can greatly help speed up and testing small bits of code and hence worth looking in to.
As for a list of well known and often used web frameworks, look into the following frameworks**:
Twisted[13] is a generic networking framework, which supports almost every single protocol under the sun.
Pylons[14] is light-weight framework aimed at being as flexible as possible and leaving all the choices about what ORM, templating language and what-not to you.
CherryPy[15] tries to provide an interface to expose Python objects to the web.
Django[6] attempts to be an all-in-one solution, builtin template system, ORM, admin pages and internationalization. While the previous frameworks have more DIY wiring together various frameworks work involved with them.
Zope[5] is aimed to be suitable for large enterprise applications, I've heard nothing but good things about it, but consensus seems to be that for smaller you're probably better off with one of the simpler and smaller frameworks.
TurboGears[16] is the framework I know the least about, but it seems to be mostly competition for Django.
This is everything I can think of right now, I'll edit and add stuff if I can think of it. I hope this helps you some in the wonderful world of python.
* - The main exception would be Apache's mod_python, which you should avoid for exactly that reason, use mod_wsgi instead.
** - Word of warning, I have not personally used these frameworks this is just a very short impression I have gotten from talking to other people about each framework, it may be wildly inaccurate. (If anyone has any corrections, do comment and I'll try to edit and fix this answer).
(The http:// is missing since they're recognized as links otherwise)
[1] www.wingware.com/
[2] www.eclipse.org/
[3] pydev.sourceforge.net/
[4] wsgi.org/wsgi/
[5] www.zope.org/
[6] www.djangoproject.com/
[7] www.sqlalchemy.org/
[8] www.sqlobject.org/
[9] docs.python.org/library/unittest.html
[10] pyunit.sourceforge.net/pyunit.html
[11] www.bpython-interpreter.org/
[12] ipython.scipy.org/
[13] twistedmatrix.com/trac/
[14] pylonshq.com/
[15] www.cherrypy.org/
[16] turbogears.org/ | 3 | 9 | 0 | I currently work with .NET exclusively and would like to have a go at python. To this end I need to set up a python development environment. I guide to this would be handy. I guess I would be doing web development so will need a web server and probably a database. I also need pointers to popular ORM's, an MVC framework, and a testing library.
One of my main criteria with all this is that I want to understand how it works, and I want it to be as isolated as possible. This is important as i am wary of polluting what is a working .NET environment with 3rd party web and database servers. I am perfectly happy using SQLite to start with if this is possible.
If I get on well with this I am also likely to want to set up automated build and ci server (On a virtual machine, probably ubuntu). Any suggestions for these would be useful.
My ultimate aim if i like python is to have similar sorts of tools that i have available with .NET and to really understand the build and deployment of it all. To start with I will settle for a simple development environment that is as isolated as possible and will be easy to remove if I don't like it. I don't want to use IronPython as I want the full experience of developing a python solution using the tools and frameworks that are generally used. | I need a beginners guide to setting up windows for python development | 0.019997 | 0 | 0 | 1,647 |
959,479 | 2009-06-06T11:08:00.000 | 0 | 0 | 1 | 0 | python,windows,development-environment | 959,891 | 10 | false | 0 | 0 | Python has build in SQL like database and web server, so you wouldn't need to install any third party apps. Remember Python comes with batteries included. | 3 | 9 | 0 | I currently work with .NET exclusively and would like to have a go at python. To this end I need to set up a python development environment. I guide to this would be handy. I guess I would be doing web development so will need a web server and probably a database. I also need pointers to popular ORM's, an MVC framework, and a testing library.
One of my main criteria with all this is that I want to understand how it works, and I want it to be as isolated as possible. This is important as i am wary of polluting what is a working .NET environment with 3rd party web and database servers. I am perfectly happy using SQLite to start with if this is possible.
If I get on well with this I am also likely to want to set up automated build and ci server (On a virtual machine, probably ubuntu). Any suggestions for these would be useful.
My ultimate aim if i like python is to have similar sorts of tools that i have available with .NET and to really understand the build and deployment of it all. To start with I will settle for a simple development environment that is as isolated as possible and will be easy to remove if I don't like it. I don't want to use IronPython as I want the full experience of developing a python solution using the tools and frameworks that are generally used. | I need a beginners guide to setting up windows for python development | 0 | 0 | 0 | 1,647 |
960,467 | 2009-06-06T20:33:00.000 | 3 | 0 | 0 | 0 | python,qt,widget,designer | 1,235,766 | 3 | false | 0 | 1 | I have a single main window with a QGraphicsView and lots of QGraphicsItem objects. Each type of the Items have a different context menu.
I find that not being able to create the contextMenu's, or at least the actions that are in them a serious limitation of QtDesigner. It means that I can create about 10% or so of the actions using the designer, and I have to create 90% programaticaly. Compare that with the Microsoft resource editor which allows all of these things to be created, and maintained effortlessly.
I hope this will be addressed at some point. | 3 | 1 | 0 | Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this. | how can I add a QMenu and QMenuItems to a window from Qt Designer | 0.197375 | 0 | 0 | 3,989 |
960,467 | 2009-06-06T20:33:00.000 | 3 | 0 | 0 | 0 | python,qt,widget,designer | 960,506 | 3 | true | 0 | 1 | When you edit a QMainWindow you can right click the window and then choose "create menu bar".
Or are you talking about a "context menu" aka "right click menu"? | 3 | 1 | 0 | Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this. | how can I add a QMenu and QMenuItems to a window from Qt Designer | 1.2 | 0 | 0 | 3,989 |
960,467 | 2009-06-06T20:33:00.000 | 0 | 0 | 0 | 0 | python,qt,widget,designer | 960,479 | 3 | false | 0 | 1 | Adding menu editing for every widget in the designer would probably make a very awkward and inconvenient UI. There's really no place you can visualize it on.
If you're editing a QMainWindow you can edit the menu bar and its popups because there's a proper place for them to be displayed in. | 3 | 1 | 0 | Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this. | how can I add a QMenu and QMenuItems to a window from Qt Designer | 0 | 0 | 0 | 3,989 |
961,263 | 2009-06-07T05:27:00.000 | 0 | 0 | 1 | 0 | python,variables,input | 69,707,808 | 19 | false | 0 | 0 | In short, using list comprehension and split()
Python 3:
var1, var2 = [int(num) for num in input("Enter two numbers separated by space: ").split()] | 3 | 42 | 0 | This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?
For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.
Does anyone out there know a good way to do this elegantly and concisely? | Two values from one input in python? | 0 | 0 | 0 | 192,265 |
961,263 | 2009-06-07T05:27:00.000 | 1 | 0 | 1 | 0 | python,variables,input | 45,059,561 | 19 | false | 0 | 0 | This is a sample code to take two inputs seperated by split command and delimiter as ","
>>> var1, var2 = input("enter two numbers:").split(',')
>>>enter two numbers:2,3
>>> var1
'2'
>>> var2
'3'
Other variations of delimiters that can be used are as below :
var1, var2 = input("enter two numbers:").split(',')
var1, var2 = input("enter two numbers:").split(';')
var1, var2 = input("enter two numbers:").split('/')
var1, var2 = input("enter two numbers:").split(' ')
var1, var2 = input("enter two numbers:").split('~') | 3 | 42 | 0 | This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?
For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.
Does anyone out there know a good way to do this elegantly and concisely? | Two values from one input in python? | 0.010526 | 0 | 0 | 192,265 |
961,263 | 2009-06-07T05:27:00.000 | 3 | 0 | 1 | 0 | python,variables,input | 46,063,803 | 19 | false | 0 | 0 | The solution I found is the following:
Ask the user to enter two numbers separated by a comma or other character
value = input("Enter 2 numbers (separated by a comma): ")
Then, the string is split: n takes the first value and m the second one
n,m = value.split(',')
Finally, to use them as integers, it is necessary to convert them
n, m = int(n), int(m) | 3 | 42 | 0 | This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?
For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.
Does anyone out there know a good way to do this elegantly and concisely? | Two values from one input in python? | 0.031568 | 0 | 0 | 192,265 |
961,465 | 2009-06-07T08:08:00.000 | 6 | 0 | 0 | 0 | python,error-handling,sockets | 961,484 | 1 | true | 0 | 0 | It appears Python is exposing the error code from the OS - the interpretation of the code is OS-dependent.
111 is ECONNREFUSED on many Linux systems, and on Cygwin.
146 is ECONNREFUSED on Solaris.
10061 is WSAECONNREFUSED in winerror.h - it's the Windows Socket API's version of ECONNREFUSED.
No doubt on other systems, it's different again.
The correct way to handle this is use symbolic comparisons based on the OS's definition of ECONNREFUSED; that's the way you do it in C, for example. In other words, have a constant called ECONNREFUSED that has the value of ECONNREFUSED for that platform, in a platform-specific library (which will be necessary to link to the OS's socket primitives in any case), and compare error codes with the ECONNREFUSED constant, rather than magic numbers.
I don't know what Python's standard approach to OS error codes is. I suspect it's not terribly well thought out. | 1 | 2 | 0 | I use python 2.4.1 on Linux, and a python package written inside the company I work in, for establishing a connection between 2 hosts for test purposes.
Upon establishing the connection the side defined as the client side failed when calling socket.connect with the correct parameters (I checked) with the error code 111. After searching the web for this error means, I learned that it means that the connection was actively refused.
But the code in the package for establishing the connection is supposed to deal with it, only it knows 10061 as the error code for this same error: The connection is refused.
Could it be that there are identical error codes for the same logical errors? Could it be that 111 is a system error of the Linux OS, as 10061 is python's or even another OS? Even so, isn't the entire concept of error codes to unify the logical errors with the same codes?
Should I simply add the 111 error code to the handling condition? | Identical Error Codes | 1.2 | 0 | 1 | 867 |
961,735 | 2009-06-07T11:19:00.000 | 0 | 0 | 0 | 0 | python,gtk,pygtk | 962,054 | 2 | false | 0 | 1 | I don't know if this applies to gtk.EntryCompletion widgets, but for cell like widgets you can control their height with the cell.set_fixed_height_from_font(True) method.
Look at the gtk.CellRendererText API for details. | 2 | 2 | 0 | I use gtk.EntryCompletion to implement the autocomletion function.
But the list is so long that the pop-up window touches the bottom of screen.
And I cant find the method of set the height of pop-up window in doc of pygtk.
How to set the height of pop-up window in gtk.EntryCompletion? | pygtk: How to set the height of pop-up window in gtk.EntryCompletion | 0 | 0 | 0 | 509 |
961,735 | 2009-06-07T11:19:00.000 | 0 | 0 | 0 | 0 | python,gtk,pygtk | 7,963,132 | 2 | false | 0 | 1 | Maybe you can solve the problem using gtk.EntryCompletion.set_minimum_key_length to prevent long list of suggestions. | 2 | 2 | 0 | I use gtk.EntryCompletion to implement the autocomletion function.
But the list is so long that the pop-up window touches the bottom of screen.
And I cant find the method of set the height of pop-up window in doc of pygtk.
How to set the height of pop-up window in gtk.EntryCompletion? | pygtk: How to set the height of pop-up window in gtk.EntryCompletion | 0 | 0 | 0 | 509 |
961,972 | 2009-06-07T14:29:00.000 | 1 | 0 | 1 | 0 | python | 27,588,519 | 4 | false | 0 | 0 | try to make sure the value whose log you are trying to find can never be 0. As log(0) tends to negative infinity, the function call will give you a math domain error. Correct that and I think you'll be fine. | 2 | 4 | 0 | i want to find out a log10 of an integer in python and i get an error like
math domain error
my code is this
w=math.log10(q*q1)/math.log10(2)
where q1,q2 are integers
yeah q1 is 0 sometimes | python logarithm | 0.049958 | 0 | 0 | 20,690 |
961,972 | 2009-06-07T14:29:00.000 | 9 | 0 | 1 | 0 | python | 961,977 | 4 | true | 0 | 0 | Is q or q1 equal to zero or one of them negative? | 2 | 4 | 0 | i want to find out a log10 of an integer in python and i get an error like
math domain error
my code is this
w=math.log10(q*q1)/math.log10(2)
where q1,q2 are integers
yeah q1 is 0 sometimes | python logarithm | 1.2 | 0 | 0 | 20,690 |
963,080 | 2009-06-08T00:08:00.000 | 2 | 0 | 0 | 1 | python,google-app-engine | 972,243 | 4 | false | 1 | 0 | If you're using the 'webapp' framework included with App Engine (or, actually, most other WSGI-baesd frameworks), a new RequestHandler is instantiated for each request. Thus, you can use class variables on your handler class to store per-request data. | 3 | 0 | 0 | I'm creating a python app for google app engine and I've got a performance problem with some expensive operations that are repetitive within a single request. To help deal with this I'd like to create a sort of mini-cache that's scoped to a single request. This is as opposed to a session-wide or application-wide cache, neither of which would make sense for my particular problem.
I thought I could just use a python global or module-level variable for this, but it turns out that those maintain their state between requests in non-obvious ways.
I also don't think memcache makes sense because it's application wide.
I haven't been able to find a good answer for this in google's docs. Maybe that's because it's either a dumb idea or totally obvious, but it seems like it'd be useful and I'm stumped.
Anybody have any ideas? | How can I create a variable that is scoped to a single request in app engine? | 0.099668 | 0 | 0 | 211 |
963,080 | 2009-06-08T00:08:00.000 | 0 | 0 | 0 | 1 | python,google-app-engine | 963,706 | 4 | false | 1 | 0 | use local list to store data and do a model.put at end of your request processing. save multiple db trips | 3 | 0 | 0 | I'm creating a python app for google app engine and I've got a performance problem with some expensive operations that are repetitive within a single request. To help deal with this I'd like to create a sort of mini-cache that's scoped to a single request. This is as opposed to a session-wide or application-wide cache, neither of which would make sense for my particular problem.
I thought I could just use a python global or module-level variable for this, but it turns out that those maintain their state between requests in non-obvious ways.
I also don't think memcache makes sense because it's application wide.
I haven't been able to find a good answer for this in google's docs. Maybe that's because it's either a dumb idea or totally obvious, but it seems like it'd be useful and I'm stumped.
Anybody have any ideas? | How can I create a variable that is scoped to a single request in app engine? | 0 | 0 | 0 | 211 |
963,080 | 2009-06-08T00:08:00.000 | 1 | 0 | 0 | 1 | python,google-app-engine | 963,107 | 4 | false | 1 | 0 | Module variables may (or may not) persist between requests (the same app instance may or may not stay alive between requests), but you can explicitly clear them (del, or set to None, say) at the start of your handling a request, or when you know you're done with one. At worst (if your code is peculiarly organized) you need to set some function to always execute at every request start, or at every request end. | 3 | 0 | 0 | I'm creating a python app for google app engine and I've got a performance problem with some expensive operations that are repetitive within a single request. To help deal with this I'd like to create a sort of mini-cache that's scoped to a single request. This is as opposed to a session-wide or application-wide cache, neither of which would make sense for my particular problem.
I thought I could just use a python global or module-level variable for this, but it turns out that those maintain their state between requests in non-obvious ways.
I also don't think memcache makes sense because it's application wide.
I haven't been able to find a good answer for this in google's docs. Maybe that's because it's either a dumb idea or totally obvious, but it seems like it'd be useful and I'm stumped.
Anybody have any ideas? | How can I create a variable that is scoped to a single request in app engine? | 0.049958 | 0 | 0 | 211 |
963,932 | 2009-06-08T08:47:00.000 | 0 | 0 | 1 | 0 | python,django,google-app-engine,list | 965,860 | 3 | false | 1 | 0 | There is no specific change "inherent" in appengine with respect to common aspects like lists. It is as just the same, plain python. | 1 | 0 | 0 | I am trying to convert a set object to list...for example "p=list('abc')" is not working.
any ideas or is it inherent in appengine | Can't seem to get list() working | 0 | 0 | 0 | 275 |
964,123 | 2009-06-08T09:49:00.000 | 0 | 0 | 0 | 0 | python,trac,netbeans6.5 | 964,191 | 5 | false | 0 | 0 | Usually, we unit test first.
Then, we write log messages to diagnose problems.
We generally don't depend heavily on debugging because it's often hard to do in situations where Python scripts are embedded in a larger product. | 1 | 4 | 0 | I'm about to start a fair amount of work extending Trac to fit our business requirements.
So far I've used pythonWin and now Netbeans 6.5 as the development environments - neither of these seem to provide any way of debugging the plugin I am working on.
I'm totally new to Python so probably have not set up the development environment how it could be congfigured to get it debugging.
Am I missing something obvious? It seems a bit archaic to have to resort to printing debug messages to the Trac log, which is how I'm debugging at the moment. | How should I debug Trac plugins? | 0 | 0 | 0 | 1,146 |
964,459 | 2009-06-08T11:30:00.000 | -1 | 0 | 1 | 0 | javascript,python | 964,478 | 9 | false | 0 | 0 | I don't know Python good enough to tell you a solution. But if you want to use that to sanitize the user input you have to be very, very careful. Removing stuff between and just doesn't catch everything. Maybe you can have a look at existing solutions (I assume Django includes something like this). | 2 | 5 | 0 | how to remove text between <script> and </script> using python? | how to remove text between using python? | -0.022219 | 0 | 0 | 10,944 |
964,459 | 2009-06-08T11:30:00.000 | 0 | 0 | 1 | 0 | javascript,python | 964,487 | 9 | false | 0 | 0 | If you're removing everything between <script> and </script> why not just remove the entire node?
Are you expecting a resig-style src and body? | 2 | 5 | 0 | how to remove text between <script> and </script> using python? | how to remove text between using python? | 0 | 0 | 0 | 10,944 |
965,694 | 2009-06-08T16:13:00.000 | 12 | 0 | 1 | 0 | python,settings | 966,074 | 13 | false | 1 | 0 | Just one more option, PyQt. Qt has a platform independent way of storing settings with the QSettings class. Underneath the hood, on windows it uses the registry and in linux it stores the settings in a hidden conf file. QSettings works very well and is pretty seemless. | 6 | 65 | 0 | Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.
Are one of these approaches blessed by Guido and/or the Python community more than another? | What's the official way of storing settings for Python programs? | 1 | 0 | 0 | 43,088 |
965,694 | 2009-06-08T16:13:00.000 | 35 | 0 | 1 | 0 | python,settings | 965,795 | 13 | true | 1 | 0 | Depends on the predominant intended audience.
If it is programmers who change the file anyway, just use python files like settings.py
If it is end users then, think about ini files. | 6 | 65 | 0 | Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.
Are one of these approaches blessed by Guido and/or the Python community more than another? | What's the official way of storing settings for Python programs? | 1.2 | 0 | 0 | 43,088 |
965,694 | 2009-06-08T16:13:00.000 | -1 | 0 | 1 | 0 | python,settings | 965,733 | 13 | false | 1 | 0 | why would Guido blessed something that is out of his scope? No there is nothing particular blessed. | 6 | 65 | 0 | Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.
Are one of these approaches blessed by Guido and/or the Python community more than another? | What's the official way of storing settings for Python programs? | -0.015383 | 0 | 0 | 43,088 |
965,694 | 2009-06-08T16:13:00.000 | 0 | 0 | 1 | 0 | python,settings | 965,742 | 13 | false | 1 | 0 | It is more of convenience. There is no official way per say. But using XML files would make sense as they can be manipulated by various other applications/libraries. | 6 | 65 | 0 | Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.
Are one of these approaches blessed by Guido and/or the Python community more than another? | What's the official way of storing settings for Python programs? | 0 | 0 | 0 | 43,088 |
965,694 | 2009-06-08T16:13:00.000 | 4 | 0 | 1 | 0 | python,settings | 965,913 | 13 | false | 1 | 0 | It depends largely on how complicated your configuration is. If you're doing a simple key-value mapping and you want the capability to edit the settings with a text editor, I think ConfigParser is the way to go.
If your settings are complicated and include lists and nested data structures, I'd use XML or JSON and create a configuration editor.
For really complicated things where the end user isn't expected to change the settings much, or is more trusted, just create a set of Python classes and evaluate a Python script to get the configuration. | 6 | 65 | 0 | Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.
Are one of these approaches blessed by Guido and/or the Python community more than another? | What's the official way of storing settings for Python programs? | 0.061461 | 0 | 0 | 43,088 |
965,694 | 2009-06-08T16:13:00.000 | 6 | 0 | 1 | 0 | python,settings | 965,730 | 13 | false | 1 | 0 | I am not sure that there is an 'official' way (it is not mentioned in the Zen of Python :) )- I tend to use the Config Parser module myself and I think that you will find that pretty common. I prefer that over the python file approach because you can write back to it and dynamically reload if you want. | 6 | 65 | 0 | Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.
Are one of these approaches blessed by Guido and/or the Python community more than another? | What's the official way of storing settings for Python programs? | 1 | 0 | 0 | 43,088 |
967,369 | 2009-06-08T22:36:00.000 | 6 | 0 | 0 | 1 | python,shell,terminal,stdout | 967,383 | 4 | false | 0 | 0 | You can use os.getppid() to find out the process id for the parent-process of this one, and then use that process id to determine which program that process is running. More usefully, you could use sys.stdout.isatty() -- that doesn't answer your title question but appears to better solve the actual problem you explain (if you're running under a shell but your output is piped to some other process or redirected to a file you probably don't want to emit "interactive stuff" on it either). | 1 | 7 | 0 | is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?
the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not.
thanks!
p. | python: find out if running in shell or not (e.g. sun grid engine queue) | 1 | 0 | 0 | 1,762 |
967,661 | 2009-06-09T00:29:00.000 | 1 | 0 | 1 | 0 | python,truncate | 967,676 | 8 | false | 0 | 0 | You have several options - you can round the number using round(), however this can introduce some inaccuracies (315.15 might round to 315.150000003 for example). If you're just looking to truncate the value of the float when you're displaying it, you can specify the width of the output using printf("%.2f", mynumber). This is probably a better solution, since without knowing more about your specific application it's a good idea in general to keep the entire length of the number for calculation. | 1 | 12 | 0 | How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15
how do i do that? | python truncate after a hundreds? | 0.024995 | 0 | 0 | 38,627 |
968,317 | 2009-06-09T05:36:00.000 | 0 | 0 | 0 | 0 | python,image-processing,opencv,color-space | 968,351 | 3 | false | 0 | 0 | How about using a formular like r' = r-(g+b)? | 2 | 1 | 1 | I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish.
I tried to take only the red color channel but this includes the white spaces in the Image too.
What is a good way to do that? | How to isolate a single color in an image | 0 | 0 | 0 | 2,798 |
968,317 | 2009-06-09T05:36:00.000 | 1 | 0 | 0 | 0 | python,image-processing,opencv,color-space | 2,204,755 | 3 | false | 0 | 0 | Use the HSV colorspace. Select pixels that have an H value in the range that you consider to contain "red," and an S value large enough that you do not consider it to be neutral, maroon, brown, or pink. You might also need to throw out pixels with low V's. The H dimension is a circle, and red is right where the circle is split, so your H range will be in two parts, one near 255, the other near 0. | 2 | 1 | 1 | I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish.
I tried to take only the red color channel but this includes the white spaces in the Image too.
What is a good way to do that? | How to isolate a single color in an image | 0.066568 | 0 | 0 | 2,798 |
969,093 | 2009-06-09T09:37:00.000 | 0 | 0 | 1 | 0 | python | 52,444,195 | 10 | false | 0 | 0 | help(name of the function)
if you are using jupyter or ipython notebook ,then adding "?" would bring dogstring for the code. this is helpful if you want to see help of specific function.example pandas.read_csv?.
by pressing "Tab" you can see what you need to enter as parameters, although it would not give what a function does, but provide way to enter the input parameters. | 2 | 9 | 0 | Is there any way to search for a particular package/function using keywords in the Python console?
For example, I may want to search "pdf" for pdf related tasks. | How to search help using python console | 0 | 0 | 0 | 53,692 |
969,093 | 2009-06-09T09:37:00.000 | 5 | 0 | 1 | 0 | python | 4,670,427 | 10 | false | 0 | 0 | You can search for modules containing "pdf" in their description by running the command help("modules pdf"). | 2 | 9 | 0 | Is there any way to search for a particular package/function using keywords in the Python console?
For example, I may want to search "pdf" for pdf related tasks. | How to search help using python console | 0.099668 | 0 | 0 | 53,692 |
969,121 | 2009-06-09T09:43:00.000 | 1 | 0 | 1 | 1 | python,eclipse,cvs,pydev | 969,236 | 8 | false | 1 | 0 | I tried Eclipse+Subclipse and Eclipse+Bazaar plugin. Both work very well, but I have found that Tortoise versions of those version source control tools are so good that I resigned from Eclipse plugins. On Windows Tortoise XXX are my choice. They integrate with shell (Explorer or TotalCommander), changes icon overlay if file is changed, shows log, compare revisions etc. etc. | 4 | 4 | 0 | I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed on my local harddrive (I recently moved my house and don't have yet an access to internet.)
It doesn't matter for me if it'd be CVS - can also be any other version control system. It'd be great if it will be not too hard to configure with Eclipse. Can anyone give me some possible solution? Any hints?
Regards and thanks in advance for any clues. Please forgive my English ;) | Eclipse + local CVS + PyDev | 0.024995 | 0 | 0 | 2,673 |
969,121 | 2009-06-09T09:43:00.000 | 4 | 0 | 1 | 1 | python,eclipse,cvs,pydev | 969,642 | 8 | true | 1 | 0 | Last time I tried this, Eclipse did not support direct access to local repositories in the same way that command line cvs does because command line cvs has both client and server functionality whereas Eclipse only has client functionality and needs to go through (e.g.) pserver, so you would probably need to have a cvs server running.
Turns out that I didn't really need it anyway as Eclipse keeps its own history of all changes so I only needed to do an occasional manual update to cvs at major milestones.
[Eventually I decided not to use cvs at all with Eclipse under Linux as it got confused by symlinks and started deleting my include files when it "synchronised" with the repository.] | 4 | 4 | 0 | I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed on my local harddrive (I recently moved my house and don't have yet an access to internet.)
It doesn't matter for me if it'd be CVS - can also be any other version control system. It'd be great if it will be not too hard to configure with Eclipse. Can anyone give me some possible solution? Any hints?
Regards and thanks in advance for any clues. Please forgive my English ;) | Eclipse + local CVS + PyDev | 1.2 | 0 | 0 | 2,673 |
969,121 | 2009-06-09T09:43:00.000 | 0 | 0 | 1 | 1 | python,eclipse,cvs,pydev | 976,961 | 8 | false | 1 | 0 | I recently moved my house and don't have yet an access to internet.
CVS and SVN are the Centralized Version control systems. Rather than having to install them on your local system just for single version control, you could use DVCS like Mercurial or Git.
When you clone a Mercurial Repository, you have literally all versions of all the repo files available locally. | 4 | 4 | 0 | I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed on my local harddrive (I recently moved my house and don't have yet an access to internet.)
It doesn't matter for me if it'd be CVS - can also be any other version control system. It'd be great if it will be not too hard to configure with Eclipse. Can anyone give me some possible solution? Any hints?
Regards and thanks in advance for any clues. Please forgive my English ;) | Eclipse + local CVS + PyDev | 0 | 0 | 0 | 2,673 |
969,121 | 2009-06-09T09:43:00.000 | 1 | 0 | 1 | 1 | python,eclipse,cvs,pydev | 969,134 | 8 | false | 1 | 0 | If you don't mind a switch to Subversion, Eclipse has its SubClipse plugin. | 4 | 4 | 0 | I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed on my local harddrive (I recently moved my house and don't have yet an access to internet.)
It doesn't matter for me if it'd be CVS - can also be any other version control system. It'd be great if it will be not too hard to configure with Eclipse. Can anyone give me some possible solution? Any hints?
Regards and thanks in advance for any clues. Please forgive my English ;) | Eclipse + local CVS + PyDev | 0.024995 | 0 | 0 | 2,673 |
969,849 | 2009-06-09T12:40:00.000 | 1 | 0 | 0 | 0 | python,authentication | 969,860 | 4 | false | 0 | 0 | wrap the calling of your python app in a .bat file and put a shortcut to that .bat file in startup. | 3 | 1 | 0 | I have a web based email application that logs me out after 10 minutes of inactivity ("For security reasons"). I would like to write something that either a) imitates a keystroke b) pings an ip or c) some other option every 9 minutes so that I stay logged in. I am on my personal laptop in an office with a door, so I'm not too worried about needing to be logged out.
I have written a small python script to ping an ip and then sleep for 9 minutes, and this works dandy, but I would like something that I could include in my startup applications. I don't know if this means I need to compile something into an exe, or can I add this python script to startup apps? | automatic keystroke to stay logged in | 0.049958 | 0 | 0 | 650 |
969,849 | 2009-06-09T12:40:00.000 | 3 | 0 | 0 | 0 | python,authentication | 969,897 | 4 | true | 0 | 0 | You can also use the Scheduled Tasks feature (on the Control Panel) to run it at startup, or you can change your script to ping the IP and exit, and scheduled it to run every 9 minutes. You have nice settings there, for example, you can stop running it at night, so you'll still log out.
You might still need the bat file though, I don't know about Python.
In fact, if you need just a simple ping you can scheduled ping.exe. | 3 | 1 | 0 | I have a web based email application that logs me out after 10 minutes of inactivity ("For security reasons"). I would like to write something that either a) imitates a keystroke b) pings an ip or c) some other option every 9 minutes so that I stay logged in. I am on my personal laptop in an office with a door, so I'm not too worried about needing to be logged out.
I have written a small python script to ping an ip and then sleep for 9 minutes, and this works dandy, but I would like something that I could include in my startup applications. I don't know if this means I need to compile something into an exe, or can I add this python script to startup apps? | automatic keystroke to stay logged in | 1.2 | 0 | 0 | 650 |
969,849 | 2009-06-09T12:40:00.000 | 2 | 0 | 0 | 0 | python,authentication | 971,984 | 4 | false | 0 | 0 | Pinging an IP will not likely keep your session from timing out.
You will likely need to do an HTTP GET and include the session cookie supplied by the server to your browser when you login. Your script may be able to read the cookie from your browser's cookies folder after you have logged in via the browser.
Also, the web page may have javascript that calls the logout page when it times out. You may be able to use codemonkey to disable this behavior. | 3 | 1 | 0 | I have a web based email application that logs me out after 10 minutes of inactivity ("For security reasons"). I would like to write something that either a) imitates a keystroke b) pings an ip or c) some other option every 9 minutes so that I stay logged in. I am on my personal laptop in an office with a door, so I'm not too worried about needing to be logged out.
I have written a small python script to ping an ip and then sleep for 9 minutes, and this works dandy, but I would like something that I could include in my startup applications. I don't know if this means I need to compile something into an exe, or can I add this python script to startup apps? | automatic keystroke to stay logged in | 0.099668 | 0 | 0 | 650 |
969,877 | 2009-06-09T12:48:00.000 | 1 | 0 | 0 | 1 | python,google-app-engine | 14,879,943 | 1 | false | 1 | 0 | Actually not my answer, but from the OP, that didn't act on S. Lott's comment:
It works now! but I didnt change anything actually, seems like Google need time to update its database for app engine. like 20 mins. | 1 | 1 | 0 | I want to use user service of my domain in google App, but...
Is it possible to solve this problem by my side?
Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 501, in __call__
handler.get(*groups)
File "/base/data/home/apps/myapp2009/1.334081739634584397/helloworld.py", line 13, in get
self.redirect(users.create_login_url(self.request.uri))
File "/base/python_lib/versions/1/google/appengine/api/users.py", line 176, in create_login_url
raise NotAllowedError
NotAllowedError | users module errors in Google App Engine | 0.197375 | 0 | 0 | 444 |
970,909 | 2009-06-09T15:49:00.000 | 0 | 0 | 1 | 0 | java,python,multithreading | 971,025 | 6 | false | 1 | 0 | Just a sidestep about point 1 here, because Java Thread priorities might not work as one would expect.
From the SCJP guide:
Because thread-scheduling priority behaviour is not guaranteed, use thread priorities as a way to improve the efficiency of your program, but just be sure your program doesn't depend on that behaviour for correctness. | 1 | 6 | 0 | i have few questions about threads in Python and Java...
Is it possible to give priorities to Python threads, as it is in Java?
How can I kill, stop, suspend and interrupt thread in Python?
Thread groups - what are they really for? Does Python support them too?
Synchronization - in Java we use simply keyword synchorinized for a method, object...What about Python?
Tnx! | Threads in Java and Python | 0 | 0 | 0 | 2,528 |
971,983 | 2009-06-09T19:18:00.000 | 11 | 0 | 0 | 0 | python,django | 972,004 | 3 | true | 1 | 0 | There's no real rule for this, But one thing I like to do is actually arrange for the index access to redirect to another spot. If you prefer, though, you can just give the index page a plain view.
That said, It's probably a good idea to keep all your code in an actual app, so that you can refactor it more easily, and so that it appears on the python path as a normal module. Putting views in the project rather than an app seems to cause more headaches than it solves. | 1 | 20 | 0 | I've been having a look at Django and, from what I've seen, it's pretty darn fantastic. I'm a little confused, however, how I go about implementing a "home page" for my website? Would it be a separate app, or just a view within the project, or what? | Django - Website Home Page | 1.2 | 0 | 0 | 11,919 |
973,473 | 2009-06-10T02:48:00.000 | 1 | 0 | 1 | 1 | python,directory,subdirectory | 35,261,270 | 32 | false | 0 | 0 | use a filter function os.path.isdir over os.listdir()
something like this filter(os.path.isdir,[os.path.join(os.path.abspath('PATH'),p) for p in os.listdir('PATH/')]) | 2 | 824 | 0 | Is there a way to return a list of all the subdirectories in the current directory in Python?
I know you can do this with files, but I need to get the list of directories instead. | Getting a list of all subdirectories in the current directory | 0.00625 | 0 | 0 | 1,160,495 |
973,473 | 2009-06-10T02:48:00.000 | 41 | 0 | 1 | 1 | python,directory,subdirectory | 973,489 | 32 | false | 0 | 0 | If you need a recursive solution that will find all the subdirectories in the subdirectories, use walk as proposed before.
If you only need the current directory's child directories, combine os.listdir with os.path.isdir | 2 | 824 | 0 | Is there a way to return a list of all the subdirectories in the current directory in Python?
I know you can do this with files, but I need to get the list of directories instead. | Getting a list of all subdirectories in the current directory | 1 | 0 | 0 | 1,160,495 |
973,520 | 2009-06-10T03:11:00.000 | 11 | 1 | 0 | 1 | python,shell,zsh,ipython | 1,070,597 | 2 | true | 0 | 0 | I asked this question on the zsh list and this answer worked for me. YMMV.
In genutils.py after the line
if not debug:
Remove the line:
stat = os.system(cmd)
Replace it with:
stat =
subprocess.call(cmd,shell=True,executable='/bin/zsh')
you see, the problem is that that "!" call uses os.system to run it, which defaults to manky old /bin/sh .
Like I said, it worked for me, although I'm not sure what got borked behind the scenes. | 1 | 11 | 0 | I have been in love with zsh for a long time, and more recently I have been discovering the advantages of the ipython interactive interpreter over python itself. Being able to cd, to ls, to run or to ! is indeed very handy. But now it feels weird to have such a clumsy shell when in ipython, and I wonder how I could integrate my zsh and my ipython better.
Of course, I could rewrite my .zshrc and all my scripts in python, and emulate most of my shell world from ipython, but it doesn't feel right. And I am obviously not ready to use ipython as a main shell anyway.
So, here comes my question: how do you work efficiently between your shell and your python command-loop ? Am I missing some obvious integration strategy ? Should I do all that in emacs ? | how to integrate ZSH and (i)python? | 1.2 | 0 | 0 | 8,591 |
974,741 | 2009-06-10T10:18:00.000 | 0 | 0 | 0 | 0 | python,urllib2,wget | 975,759 | 10 | false | 1 | 0 | There shouldn't be a difference really. All urlretrieve does is make a simple HTTP GET request. Have you taken out your data processing code and done a straight throughput comparison of wget vs. pure python? | 5 | 9 | 0 | I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.
The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.
But, just to play around I was also using python to build my urlparser.
Downloading via Python's urlretrieve is damm slow, possible 4 times as slow as wget. The download rate is 500kb/sec. I use HTMLParser for parsing the href tags.
I am not sure why is this happening. Are there any settings for this.
Thanks | wget Vs urlretrieve of python | 0 | 0 | 1 | 37,225 |
974,741 | 2009-06-10T10:18:00.000 | 0 | 0 | 0 | 0 | python,urllib2,wget | 976,135 | 10 | false | 1 | 0 | Please show us some code. I'm pretty sure that it has to be with the code and not on urlretrieve.
I've worked with it in the past and never had any speed related issues. | 5 | 9 | 0 | I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.
The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.
But, just to play around I was also using python to build my urlparser.
Downloading via Python's urlretrieve is damm slow, possible 4 times as slow as wget. The download rate is 500kb/sec. I use HTMLParser for parsing the href tags.
I am not sure why is this happening. Are there any settings for this.
Thanks | wget Vs urlretrieve of python | 0 | 0 | 1 | 37,225 |
974,741 | 2009-06-10T10:18:00.000 | 0 | 0 | 0 | 0 | python,urllib2,wget | 2,350,655 | 10 | false | 1 | 0 | You can use wget -k to engage relative links in all urls. | 5 | 9 | 0 | I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.
The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.
But, just to play around I was also using python to build my urlparser.
Downloading via Python's urlretrieve is damm slow, possible 4 times as slow as wget. The download rate is 500kb/sec. I use HTMLParser for parsing the href tags.
I am not sure why is this happening. Are there any settings for this.
Thanks | wget Vs urlretrieve of python | 0 | 0 | 1 | 37,225 |
974,741 | 2009-06-10T10:18:00.000 | 1 | 0 | 0 | 0 | python,urllib2,wget | 7,782,898 | 10 | false | 1 | 0 | Since python suggests using urllib2 instead of urllib, I take a test between urllib2.urlopen and wget.
The result is, it takes nearly the same time for both of them to download the same file.Sometimes, urllib2 performs even better.
The advantage of wget lies in a dynamic progress bar to show the percent finished and the current download speed when transferring.
The file size in my test is 5MB.I haven't used any cache module in python and I am not aware of how wget works when downloading big size file. | 5 | 9 | 0 | I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.
The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.
But, just to play around I was also using python to build my urlparser.
Downloading via Python's urlretrieve is damm slow, possible 4 times as slow as wget. The download rate is 500kb/sec. I use HTMLParser for parsing the href tags.
I am not sure why is this happening. Are there any settings for this.
Thanks | wget Vs urlretrieve of python | 0.019997 | 0 | 1 | 37,225 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.