Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
2,632,179
2010-04-13T18:35:00.000
4
0
1
0
python,module,keyword
2,632,500
3
false
0
0
You can have a directory with a name that is a Python keyword storing your Python code. This directory should not be used as a package, since package names should be valid Python identifiers.
2
3
0
Am I allowed to have a directory named 'import' containing Python code? Or will the import command fail to parse it as a result? Is there any way around that?
Can Python directory names be keywords? E.g. 'import'?
0.26052
0
0
1,766
2,632,179
2010-04-13T18:35:00.000
0
0
1
0
python,module,keyword
2,632,321
3
false
0
0
Or will the import command fail to parse it as a result? It will indeed fail.
2
3
0
Am I allowed to have a directory named 'import' containing Python code? Or will the import command fail to parse it as a result? Is there any way around that?
Can Python directory names be keywords? E.g. 'import'?
0
0
0
1,766
2,632,466
2010-04-13T19:11:00.000
0
0
0
0
c++,python,binding
2,632,489
4
false
0
1
In short, yes. A binding is just that, an interface to a library or program written in another language, though it need not be generated using SWIG. SWIG is just a tool for automatic generation of the same...
4
6
0
I always see people mention that "Python binding" and "C Sharp binding" etc. when I am actually using their C++ libraries. What does binding mean? If the library is written in C, and does Python binding means that they use SWIG kind of tool to mock a Python interface? Newbie in this field, and any suggestion will be welcomed.
What does binding mean exactly?
0
0
0
1,840
2,632,466
2010-04-13T19:11:00.000
2
0
0
0
c++,python,binding
2,632,491
4
true
0
1
When someone talks about something like a "C# binding" of a library, they are indicating that you and API is being provided in C# for a library written in a different language. This may or may not involve an autogeneration tool like SWIG.
4
6
0
I always see people mention that "Python binding" and "C Sharp binding" etc. when I am actually using their C++ libraries. What does binding mean? If the library is written in C, and does Python binding means that they use SWIG kind of tool to mock a Python interface? Newbie in this field, and any suggestion will be welcomed.
What does binding mean exactly?
1.2
0
0
1,840
2,632,466
2010-04-13T19:11:00.000
0
0
0
0
c++,python,binding
2,632,492
4
false
0
1
You're right, for a general library, a "binding" essentially means "easily callable from". The binding may or may not have been created with SWIG, that's just one way to do it.
4
6
0
I always see people mention that "Python binding" and "C Sharp binding" etc. when I am actually using their C++ libraries. What does binding mean? If the library is written in C, and does Python binding means that they use SWIG kind of tool to mock a Python interface? Newbie in this field, and any suggestion will be welcomed.
What does binding mean exactly?
0
0
0
1,840
2,632,466
2010-04-13T19:11:00.000
0
0
0
0
c++,python,binding
2,632,493
4
false
0
1
If the library is written in C, and does Python binding means that they use SWIG kind of tool to mock a Python interface? Yes, you are right. That will be called a Python binding of the respective library.
4
6
0
I always see people mention that "Python binding" and "C Sharp binding" etc. when I am actually using their C++ libraries. What does binding mean? If the library is written in C, and does Python binding means that they use SWIG kind of tool to mock a Python interface? Newbie in this field, and any suggestion will be welcomed.
What does binding mean exactly?
0
0
0
1,840
2,633,029
2010-04-13T20:38:00.000
0
1
0
1
python,android,ase,android-scripting
5,914,317
1
true
1
0
The newer versions of ASE now include a function call to create these identifiers.
1
2
0
I am working on am Android Scripting Environment (ASE) script in Python to replicate an iPhone app. I need a device UID of some sort. My thoughts where a salted MD5 hash of the MAC address or device phone number, but I can't figure out how to access either of those using the Python APIs within ASE. What can I do to create a UID in Python in ASE?
How to get a Device Specific UID using Python in ASE on Android?
1.2
0
0
234
2,633,302
2010-04-13T21:20:00.000
1
0
0
0
c++,python,c
2,645,336
3
false
0
0
The crawler is very likely written in C or C++, at least backrub's crawler was written in one of these. Be aware that the crawler only takes a snapshot of the page, then stores it in a temporary database for later processing. The indexing and other attached algorithms will extract the data, for example the image references.
2
0
0
Does anyone know any more details about google's web-crawler (aka GoogleBot)? I was curious about what it was written in (I've made a few crawlers myself and am about to make another) and if it parses images and such. I'm assuming it does somewhere along the line, b/c the images in images.google.com are all resized. It also wouldn't surprise me if it was all written in Python and if they used all their own libraries for most everything, including html/image/pdf parsing. Maybe they don't though. Maybe it's all written in C/C++. Thanks in advance-
Google Bot information?
0.066568
0
1
400
2,633,302
2010-04-13T21:20:00.000
0
0
0
0
c++,python,c
2,633,356
3
true
0
0
Officially allowed languages at Google, I think, are Python/C++/Java. The bot likely uses all 3 for different tasks.
2
0
0
Does anyone know any more details about google's web-crawler (aka GoogleBot)? I was curious about what it was written in (I've made a few crawlers myself and am about to make another) and if it parses images and such. I'm assuming it does somewhere along the line, b/c the images in images.google.com are all resized. It also wouldn't surprise me if it was all written in Python and if they used all their own libraries for most everything, including html/image/pdf parsing. Maybe they don't though. Maybe it's all written in C/C++. Thanks in advance-
Google Bot information?
1.2
0
1
400
2,633,900
2010-04-13T23:28:00.000
0
0
0
0
python
2,634,849
3
false
0
1
I checked out pyglet, and saw that it works well for static per pixel collision, when the image is not manipulated too much; however, I'm not sure how well it works with a dynamic image. In short, I'm looking for a library that's able to quickly display a buffer of pixels. This buffer will be constantly changing, so fast access and blitting is essential. This could be done in C with relative ease using SDL; however, I'm looking for a similar method in Python. I'm not even too worried about hardware acceleration at this point, although it would certainly be nice.
1
2
0
So I'm going through the beginning stages of producing a game in Python, and I'm looking for a library that is able to manipulate pixels and blit them relatively fast. My first thought was pygame, as it deals in pure 2D surfaces, but it only allows pixel access through pygame.get_at(), pygame.set_at() and pygame.get_buffer(), all of which lock the surface each time they're called, making them slow to use. I can also use the PixelArray and surfarray classes, but they are locked for the duration of their lifetimes, and the only way to blit them to a surface is to either copy the pixels to a new surface, or use surfarray.blit_array, which requires creating a subsurface of the screen and blitting it to that, if the array is smaller than the screen (if it's bigger I can just use a slice of the array, which is no problem). I don't have much experience with PyOpenGL or Pyglet, but I'm wondering if there is a faster library for doing pixel manipulation in, or if there is a faster method, in Pygame, for doing pixel manupilation. I did some work with SDL and OpenGL in C, and I do like the idea of adding vertex/fragment shaders to my program. My program will chiefly be dealing in loading images and writing/reading to/from surfaces.
Python pixel manipulation library
0
0
0
2,106
2,634,119
2010-04-14T00:24:00.000
0
0
0
0
python,macos,opengl,wxpython,pyqt
2,999,881
4
false
0
1
Use an App like Picasa (now available on mac). Use AppleScript through Python to control it from your application. Failing that, use PyObjC to create Cocoa image display component and dialogs, and so on.
2
3
0
Frustrated by lack of a simple ACDSee equivalent for OS X, I'm looking to hack one up for myself. I'm looking for a gui library that accommodates: Full screen image display High quality image fit-to-screen (for display) Low memory usage Fast display Reasonable learning curve (the simpler the better) Looks like there are several choices, so which is the best? Here are some I've run across: PyOpenGL PyGame PyQT wxpython I don't have any particular experience with any of these, nor any strong desire to become an expert - I'm looking for the simplest solution. What do you recommend? [Update] For those not familiar with ACDSee, here's what it does that I care about: Simple list/thubmnail display of images in a directory Sort by name/size/type Ability to view images full screen Single-key delete while viewing full screen Move to next/previous image while viewing full screen Ability to select a group of images for: move to / copy to directory delete resize ACDSee has a bunch of niceties as well, such as remembering directories you've moved images to in the past, remembering your resize settings, displaying the total size of the images you've selected, etc. I've tried most of the options I could find (including Xee) and none of them quite get there. Please keep in mind that this is a programming/library question, not a criticism of any of the existing tools.
Python: OSX Library for fast full screen jpg/png display
0
0
0
1,562
2,634,119
2010-04-14T00:24:00.000
0
0
0
0
python,macos,opengl,wxpython,pyqt
2,647,147
4
false
0
1
it's not an answer to your coding question but for (a big part of) the lack of ACDsee equivalent (requires OSX 10.5+): Simple list/thubmnail display of images in a directory: Finder.app Sort by name/size/type: Finder.app will do name & type, not image size (but does file size) Ability to view images full screen: quick preview (spacebar / eye icon) Single-key delete while viewing full screen: command-backspace while viewing in quickpreview, both windowed and fullscreen Move to next/previous image while viewing full screen: both quickprewiew (after selecting a group of images or whole directory with cmd-a) and Preview.app Ability to select a group of images for[...]: Finder.app will does all but resize seems like you have everything except resize just pressing the spacebar while in finder. Preview.app will resize both a single image or multiple ones in one batch.
2
3
0
Frustrated by lack of a simple ACDSee equivalent for OS X, I'm looking to hack one up for myself. I'm looking for a gui library that accommodates: Full screen image display High quality image fit-to-screen (for display) Low memory usage Fast display Reasonable learning curve (the simpler the better) Looks like there are several choices, so which is the best? Here are some I've run across: PyOpenGL PyGame PyQT wxpython I don't have any particular experience with any of these, nor any strong desire to become an expert - I'm looking for the simplest solution. What do you recommend? [Update] For those not familiar with ACDSee, here's what it does that I care about: Simple list/thubmnail display of images in a directory Sort by name/size/type Ability to view images full screen Single-key delete while viewing full screen Move to next/previous image while viewing full screen Ability to select a group of images for: move to / copy to directory delete resize ACDSee has a bunch of niceties as well, such as remembering directories you've moved images to in the past, remembering your resize settings, displaying the total size of the images you've selected, etc. I've tried most of the options I could find (including Xee) and none of them quite get there. Please keep in mind that this is a programming/library question, not a criticism of any of the existing tools.
Python: OSX Library for fast full screen jpg/png display
0
0
0
1,562
2,634,394
2010-04-14T01:57:00.000
5
0
1
0
python
2,634,412
5
false
1
0
It is absolutely proper to do so. A module groups related functionality. If that functionality is implemented in several classes (e.g., Tree, Node, Leaf) then it is appropriate to place them together. A module is more closely associated with a Java package than a Java class. You can also implement a module as a folder, named for the module, with an __init__.py file inside (so Python can identify the module as such; the __init__.py may also optionally include initialization code and lists of classes, functions, and sub-packages to export.)
2
42
0
I'm very new to Python (I'm coming from a JAVA background) and I'm wondering if anyone could help me with some of the Python standards. Is it a normal or "proper" practice to put multiple class in a module? I have been working with Django and started with the tutorials and they place their database model classes in the same module. Is this something that is normally done or should I stick with 1 class per module? Is there a reason I would do one over the other? Hope I'm being clear and not to generic. Thanks to everyone in advance!
Multiple classes in a Python module
0.197375
0
0
44,756
2,634,394
2010-04-14T01:57:00.000
8
0
1
0
python
2,634,436
5
false
1
0
When in doubt, just look at Python's standard libraries :) For example, the standard calendar module contains 31 classes. So yes, it is ok.
2
42
0
I'm very new to Python (I'm coming from a JAVA background) and I'm wondering if anyone could help me with some of the Python standards. Is it a normal or "proper" practice to put multiple class in a module? I have been working with Django and started with the tutorials and they place their database model classes in the same module. Is this something that is normally done or should I stick with 1 class per module? Is there a reason I would do one over the other? Hope I'm being clear and not to generic. Thanks to everyone in advance!
Multiple classes in a Python module
1
0
0
44,756
2,634,552
2010-04-14T02:44:00.000
13
0
1
0
python,operator-overloading
2,634,723
3
true
0
0
The problem with the container using the objects' __str__ would be the total ambiguity -- what would it mean, say, if print L showed [1, 2]? L could be ['1, 2'] (a single item list whose string item contains a comma) or any of four 2-item lists (since each item can be a string or int). The ambiguity of type is common for print of course, but the total ambiguity for number of items (since each comma could be delimiting items or part of a string item) was the decisive consideration.
1
11
0
I've noticed that when an instance with an overloaded __str__ method is passed to the print function as an argument, it prints as intended. However, when passing a container that contains one of those instances to print, it uses the __repr__ method instead. That is to say, print(x) displays the correct string representation of x, and print(x, y) works correctly, but print([x]) or print((x, y)) prints the __repr__ representation instead. First off, why does this happen? Secondly, is there a way to correct that behavior of print in this circumstance?
Using __str__ representation for printing objects in containers
1.2
0
0
16,792
2,635,433
2010-04-14T06:57:00.000
1
0
1
1
python,linux
2,636,146
4
false
0
0
You could create an rpm easily using checkinstall. Search for checkinstall in google and download it. It will allow you to create an rpm and set the options.
1
8
0
I wrote a Python program. I would like to add to it an installation script that will set up everything necessary - like desktop icon, entry in the menu, home directory file, etc. I'm working on Linux (ubuntu). When a Python program is installed, what needs to happen in general? I know that it probably depends on the nature of the program. Can you give me some general ideas? Or, point me in the right direction? I have no idea how to look for this on Google. Thanks
Installing a Python program on Linux
0.049958
0
0
4,519
2,635,933
2010-04-14T08:35:00.000
0
1
0
0
python,boost
2,636,724
2
false
0
1
You could try putting -lpython26 when linking
2
2
0
I'm trying to use boost.python library in a C++ project (Windows + VS9) but it always tries to link against pyton25.lib. Is it possible to link with version 2.6.x of python? thanks
boost python version
0
0
0
712
2,635,933
2010-04-14T08:35:00.000
1
1
0
0
python,boost
2,636,711
2
false
0
1
You need to recompile boost-python library pointing Boost.Build to needed python version. P.S. This heals a problem of undefined references while linking with library needed. I beleive you've already turned of autolinking.
2
2
0
I'm trying to use boost.python library in a C++ project (Windows + VS9) but it always tries to link against pyton25.lib. Is it possible to link with version 2.6.x of python? thanks
boost python version
0.099668
0
0
712
2,637,480
2010-04-14T12:56:00.000
2
0
1
0
python,list
2,637,826
5
false
0
0
Based on Marcelo's solution: [name for cnt,name in enumerate(names) if (name != names[0] or cnt > 0)]
1
3
0
I have list in python which has following entries name-1 name-2 name-3 name-4 name-1 name-2 name-3 name-4 name-1 name-2 name-3 name-4 I would like remove name-1 from list except its first appearance -- resultant list should look like name-1 name-2 name-3 name-4 name-2 name-3 name-4 name-2 name-3 name-4 How to achieve this ?
parsing list in python
0.07983
0
0
5,759
2,638,327
2010-04-14T14:46:00.000
0
0
1
0
python,eclipse,interactive
2,640,761
2
true
0
0
If you run it as a debug operation in Eclipse, you should be able to set a breakpoint, and you can then examine variables, etc. But you can evaluate random python scripts via the watch functionality.
1
0
0
Let's consider 3 situations: 1) I write a pyhon module in Eclipse (pydev) and run it Ctrl-F11. The module runs and I don't have any control or access (AFAIK) to the module variables and functions. 2) I have defined a python interpreter as an external tool in Eclipse, so I can run it within Eclipse. It works fine, but it does not have tab completion. 3) I open my module with python IDLE (not eclipse) and press f5 (run). It runs on the IDLE opened window and when it finishes I have all the variables and functions form the module to play with. So I have 2 questions: a) how to enable, if possible, tab completion in python interpreter in Eclipse? If it's not possible, do I have any alternative to standard Python interpreter? b) I would like to run step 1) and then be able to continue developing / testing with python interpreter, just like I do with IDLE, but all inside Eclipse. Any suggestion? Thanks in advance
Python and Eclipse: How to use interactive console after running a module, with the module variables and functions
1.2
0
0
2,456
2,638,490
2010-04-14T15:04:00.000
0
1
0
0
python,c,sockets,buffer,send
2,638,568
3
false
0
0
Unless you're sending a truly huge amount of data, you're probably better off using one buffer. If you use a geometric progression for growing your buffer size, the number of allocations becomes an amortized constant, and the time to allocate the buffer will generally follow.
3
5
0
I'm playing around with sockets in C/Python and I wonder what is the most efficient way to send headers from a Python dictionary to the client socket. My ideas: use a send call for every header. Pros: No memory allocation needed. Cons: many send calls -- probably error prone; error management should be rather complicated use a buffer. Pros: one send call, error checking a lot easier. Cons: Need a buffer :-) malloc/realloc should be rather slow and using a (too) big buffer to avoid realloc calls wastes memory. Any tips for me? Thanks :-)
What is faster: multiple `send`s or using buffering?
0
0
1
867
2,638,490
2010-04-14T15:04:00.000
0
1
0
0
python,c,sockets,buffer,send
2,638,599
3
false
0
0
A send() call implies a round-trip to the kernel (the part of the OS which deals with the hardware directly). It has a unit cost of about a few hundred clock cycles. This is harmless unless you are trying to call send() millions of times. Usually, buffering is about calling send() only once in a while, when "enough data" has been gathered. "Enough" does not mean "the whole message" but something like "enough bytes so that the unit cost of the kernel round-trip is dwarfed". As a rule of thumb, an 8-kB buffer (8192 bytes) is traditionally considered as good. Anyway, for all performance-related questions, nothing beats an actual measure. Try it. Most of the time, there not any actual performance problem worth worrying about.
3
5
0
I'm playing around with sockets in C/Python and I wonder what is the most efficient way to send headers from a Python dictionary to the client socket. My ideas: use a send call for every header. Pros: No memory allocation needed. Cons: many send calls -- probably error prone; error management should be rather complicated use a buffer. Pros: one send call, error checking a lot easier. Cons: Need a buffer :-) malloc/realloc should be rather slow and using a (too) big buffer to avoid realloc calls wastes memory. Any tips for me? Thanks :-)
What is faster: multiple `send`s or using buffering?
0
0
1
867
2,638,490
2010-04-14T15:04:00.000
3
1
0
0
python,c,sockets,buffer,send
2,639,059
3
true
0
0
Because of the way TCP congestion control works, it's more efficient to send data all at once. TCP maintains a window of how much data it will allow to be "in the air" (sent but not yet acknowledged). TCP measures the acknowledgments coming back to figure out how much data it can have "in the air" without causing congestion (i.e., packet loss). If there isn't enough data coming from the application to fill the window, TCP can't make accurate measurements so it will conservatively shrink the window. If you only have a few, small headers and your calls to send are in rapid succession, the operating system will typically buffer the data for you and send it all in one packet. In that case, TCP congestion control isn't really an issue. However, each call to send involves a context switch from user mode to kernel mode, which incurs CPU overhead. In other words, you're still better off buffering in your application. There is (at least) one case where you're better off without buffering: when your buffer is slower than the context switching overhead. If you write a complicated buffer in Python, that might very well be the case. A buffer written in CPython is going to be quite a bit slower than the finely optimized buffer in the kernel. It's quite possible that buffering would cost you more than it buys you. When in doubt, measure. One word of caution though: premature optimization is the root of all evil. The difference in efficiency here is pretty small. If you haven't already established that this is a bottleneck for your application, go with whatever makes your life easier. You can always change it later.
3
5
0
I'm playing around with sockets in C/Python and I wonder what is the most efficient way to send headers from a Python dictionary to the client socket. My ideas: use a send call for every header. Pros: No memory allocation needed. Cons: many send calls -- probably error prone; error management should be rather complicated use a buffer. Pros: one send call, error checking a lot easier. Cons: Need a buffer :-) malloc/realloc should be rather slow and using a (too) big buffer to avoid realloc calls wastes memory. Any tips for me? Thanks :-)
What is faster: multiple `send`s or using buffering?
1.2
0
1
867
2,640,072
2010-04-14T18:40:00.000
2
0
0
0
python,django,excel,html-table
2,640,085
3
false
1
0
Use CSV. There's a module in Python ("csv") to generate it, and excel can read it natively.
1
5
0
I have an HTML table that I'd like to be able to export to an Excel file. I already have an option to export the table into an IQY file, but I'd prefer something that didn't allow the user to refresh the data via Excel. I just want a feature that takes a snapshot of the table at the time the user clicks the link/button. I'd prefer it if the feature was a link/button on the HTML page that allows the user to save the query results displayed in the table. It would also be nice if the formatting from the HTML/CSS could be retained. Is there a way to do this at all? Or, something I can modify with the IQY? I can try to provide more details if needed. Thanks in advance.
Django/Python: Save an HTML table to Excel
0.132549
0
0
9,613
2,640,880
2010-04-14T20:41:00.000
4
0
0
0
python,installation,download,tkinter
2,640,895
3
true
0
1
Any recent version of Python should come with Tkinter support. To my knowledge, you shouldn't need to install anything else.
1
0
0
Where can I download this programm?
Installation of Tkinter
1.2
0
0
324
2,642,282
2010-04-15T01:57:00.000
5
1
1
0
python,unit-testing,doctest
2,643,423
6
false
0
0
There's a concrete example in the Python standard library that persuades me that doctests alone aren't always enough, namely the decimal module. It has over 60000 individual testcases (in Lib/test/decimaltestdata); if all those were rewritten as doctests, the decimal module would become very unwieldy indeed. It's possible the number of tests could be slimmed down whilst still giving good coverage, but many of the numerical algorithms are sufficiently complicated that you need huge numbers of individual tests to cover all possible combinations of branches.
3
12
0
A fellow developer on a project I am on believes that doctests are as good as unit-tests, and that if a piece of code is doctested, it does not need to be unit-tested. I do not believe this to be the case. Can anyone provide some solid, ideally cited, examples either for or against the argument that doctests replace the need for unit-tests? Thank you -Daniel EDIT: Can anyone provide a reference showing that doctesting should not replace unit-testing?
Does Python doctest remove the need for unit-tests?
0.16514
0
0
3,655
2,642,282
2010-04-15T01:57:00.000
4
1
1
0
python,unit-testing,doctest
2,643,550
6
false
0
0
doctests are great for some uses working and up to date documentation sample tests embeded in docstrings spikes or design phases when classes API is not really clear unit tests are better in differents cases: when you need clear and somewhat complex setup/teardown when trying to get better coverage of all cases, inclusinf corner cases for keeping tests independant from each other In other words, at least for my own use, doctests are great when you focus on explaining what you are doing (docs, but also design phases) but more of a burden when you intent to use tests as a seat belt for refactoring or code coverage.
3
12
0
A fellow developer on a project I am on believes that doctests are as good as unit-tests, and that if a piece of code is doctested, it does not need to be unit-tested. I do not believe this to be the case. Can anyone provide some solid, ideally cited, examples either for or against the argument that doctests replace the need for unit-tests? Thank you -Daniel EDIT: Can anyone provide a reference showing that doctesting should not replace unit-testing?
Does Python doctest remove the need for unit-tests?
0.132549
0
0
3,655
2,642,282
2010-04-15T01:57:00.000
0
1
1
0
python,unit-testing,doctest
16,453,043
6
false
0
0
I think this is the wrong way to think about doctests. Doctests are documentation. They complement regular unit tests. Think of doctests as documentation examples that happen to be tested. The doctests should be there to illustrate the function to human users. The unit tests should test all the code, even the corner cases. If you add doctests for corner cases, or dozens of doctests, that will just make your docstring hard to read.
3
12
0
A fellow developer on a project I am on believes that doctests are as good as unit-tests, and that if a piece of code is doctested, it does not need to be unit-tested. I do not believe this to be the case. Can anyone provide some solid, ideally cited, examples either for or against the argument that doctests replace the need for unit-tests? Thank you -Daniel EDIT: Can anyone provide a reference showing that doctesting should not replace unit-testing?
Does Python doctest remove the need for unit-tests?
0
0
0
3,655
2,642,364
2010-04-15T02:24:00.000
0
0
0
0
php,.net,python,ajax,frameworks
2,642,409
4
false
1
0
Two approaches to this problem generally. One is for the framework to try and do it all, like Microsoft's ASP.NET with its Ajax toolkit. This includes server side controls that produce Ajax functionality with all client- and server-side code generated for you. For example, their UpdatePanel control allows for partial page updates via an Ajax call. However, it is not universally popular as a framework in general because their Page and Control models are sometimes seen as too heavyweight and overbloated. A second, "slimmer" approach would be to separate the concerns. Let jQuery or a similar library deal with cross-browser inconsistencies and the client side of the Ajax call, and use a simple lightweight server-side web framework, such as Groovy on Grails or Microsoft ASP.NET MVC (there are others as I'm sure people will point out). Any decent framework should be capable of easily producing either JSON or XML data in response to an Ajax call. As for browsers with Javascript disabled - this is the twenty first century. Do you really have to cater for them any more?
1
8
0
AJAX is a pain in the ass because it essentially means you'll have to write two sets of similarish code: one for browsers with JavaScript enabled and those without. Not only this, but you have to connect JavaScript events to hook into your models and display the results. And if all that weren't bad enough, you need to send an address change with the request, otherwise the user won't be able to "click back" correctly (if confused look at what happens to the address bar when you click links in GMail). We're searching for something that had the foresight and design goals with all these concerns in mind. Performance and security are also obvious major concerns. We love config-based systems as well, where you don't have to write a lot of code you just drop it into an easily read config format. It's like asking for the holy grail right?
A web framework where AJAX was not an after thought
0
0
0
495
2,643,081
2010-04-15T06:03:00.000
0
0
0
1
python,google-app-engine
34,367,657
5
false
1
0
Not enough points to provide a comment on the answers above hence the stand alone answer. If you delete the ini files as per the other answers the pathways to your projects in the launcher will likely also be gone. In my case however I simply moved the ini files out of the C:\Users\your username\Google directory and then after opening and closing the launcher successfully once I reinstated the ini files into the Google directory again, after which the launcher worked and the project pathways were retained.
3
6
0
the error is : Errors occurred See the logfile 'D:\Program Files\Google\google_appengine\launcher\GoogleAppEngineLauncher.exe.log' for details Why?
google app engine error ,and i can't open it now.(python)
0
0
0
6,342
2,643,081
2010-04-15T06:03:00.000
3
0
0
1
python,google-app-engine
31,897,510
5
false
1
0
Solution: Note: The wrong directories are stated above. Go to C:\Users\your username\Google directory. Delete google_appengine_launcher.ini and google_appengine_projects.ini Appengine should now start successfully, absent error message.
3
6
0
the error is : Errors occurred See the logfile 'D:\Program Files\Google\google_appengine\launcher\GoogleAppEngineLauncher.exe.log' for details Why?
google app engine error ,and i can't open it now.(python)
0.119427
0
0
6,342
2,643,081
2010-04-15T06:03:00.000
2
0
0
1
python,google-app-engine
17,596,077
5
false
1
0
yeah just like RyanW mentioned the link, Delete the .ini files viz. google_appengine_launcher.ini & google_appengine_projects.ini in the user Directory in folder named Google.
3
6
0
the error is : Errors occurred See the logfile 'D:\Program Files\Google\google_appengine\launcher\GoogleAppEngineLauncher.exe.log' for details Why?
google app engine error ,and i can't open it now.(python)
0.07983
0
0
6,342
2,643,321
2010-04-15T07:07:00.000
15
0
0
0
python,web-applications
2,643,669
6
true
1
0
For the context, I work at a large private bank in Switzerland, writing Enterprise applications on the J2EE stack. There are plenty of "Production Ready" web frameworks in Python. And there are plenty of large Python-based websites out there. That said, I think Python is a poor choice for an Enterprisy application. It can be used as a glue language, or a scripting language (our deployment scripts are Python). The showstopper for me is backward compatibility (Python 3.x isn't backward compatible with Python 2.x). The Python philosopy seems to be more to innovate and make the language better, smoother, and not necessarily to support programs written 10 years ago. On the Web framework side, I love Django, but it is definitely much too young and it evolves too rapidly to be used in the enterprise. I don't have much experience with other Python-based frameworks. If you want an enterprise-oriented framework, you'll have to stay with enterprise stacks (Java / .Net). On the other hand, even in the Java world, there is a tendency to use frameworks that are less enterprisy. Think Spring vs EJB2 or EJB3 being much lighter weight than EJB2. Or think Flex (which is far from an enterprise framework in my view) being used more and more in the enterprise. So if your enterprise is openminded enough, ready to jump into the future, using Django, RoR or other modern Web 2.0, community driven, Open Source, next generation, active record based frameworks ... might not be that much of a stretch ... And finally, to answer a few of your points directly : support of ORM / caching / ... : yes, but most solutions are based on active record, which is fine for 90% of what you might want to do, but is definitly not as complete / complex as JPA / Hibernate control-oriented UI : no, and you wont find a standard, so you wont find 3rd party components. The closest you might get is integration with jQuery or other JS UI frameworks dependency injection : There is a port of Spring to Python, maintained by SpringSource. But DI is not in the Python philosophy. The same problem will be resolved with functions, default arguments and closures. And we might argue that the Pythonic solution is cleaner than the Java way ... unit / integration tests : very good support, multiple test frameworks. Still, support is not as good as Java where we have tons of tools around testing. good IDE support : there are technical limitations to the ammount of support you can provide to a dynamic language, but at least both Eclipse and Netbeans have great support for Python. clustering / modularity : clustering will be resolved with a "share nothing infrastructure" and/or distributed caching. There are no solutions for modularity (in the OSGI sense) as far as I know. But I would challenge that very often OSGI is a solution for a problem we dont have in the enterprise ...
1
14
0
I heard lots of good opinions about Python language. They say it's mature, expressive etc... I'm looking for production-ready enterprise application frameworks in Python. By "production ready" I mean : supports objective-relational mapping with caching and declarative desciption (like JPA, Hibernate etc..) controls oriented user interface support - no HTML templates but something like JSF (RichFaces, Icefaces) or GWT, Vaadin, ZK component decomposition and dependency injection (like EJB or Spring) unit and integration testing good IDE support clustering, modularity etc (like Terracota, OSGi etc..) there are successful applications written in it by companies like IBM, Oracle etc (I mean real business applications not Twitter) could have commercial support Is it possible at all in Python world ? Or only choices are : use Python and write everything from the bottom (too expensice) stick to Java EE buy .NET stack
Is there a production ready web application framework in Python?
1.2
0
0
5,358
2,643,721
2010-04-15T08:23:00.000
0
0
0
0
python,django,apache,login,debugging
2,645,668
5
false
1
0
I would guess that this is related to errors in admin classes requiring the devserver to be restarted to continue. As nothing is being reportedm I would try removing all of your admin.py definitions and just use the basic admin.site.register(SomeModel) for everything and seeing if it still happens, then add them back in until it re-occurs.
4
2
0
Short Story: I get locked out of my Django app when Debug is set to False. Long story: Case 1 (the first time it happened): I enter my login info, but It just redirects to the login page. I restart the server, try to login, and it works fine, I get in. a few hours later I come back, log out, try to log back in and I can't. It just redirects to the login page. Case 2 (I figure out how to provoke the login failure): I restart the server and am able to login to the site. I log in and log out several times, everything is fine. I go to a non-existing page and get a server error. I log out and try to log back in, and I can't, just get redirected back to the login page. Case 3 (I can't provoke the login failure with Debug set to True): 1. I restart the server and am able to login to the site. 2. I log in and log out several times, everything is fine. 3. I go to a non-existing page and get a traceback. 4. I log out and log back in, everything works. 5. I wait and play around with it and can't get the login to fail while in Debug mode. Please help!
I can't login to my Django app when debug is set to False
0
0
0
1,621
2,643,721
2010-04-15T08:23:00.000
1
0
0
0
python,django,apache,login,debugging
2,644,182
5
false
1
0
Do you have a custom 500 error handler set up? Is that doing something weird with the session, perhaps?
4
2
0
Short Story: I get locked out of my Django app when Debug is set to False. Long story: Case 1 (the first time it happened): I enter my login info, but It just redirects to the login page. I restart the server, try to login, and it works fine, I get in. a few hours later I come back, log out, try to log back in and I can't. It just redirects to the login page. Case 2 (I figure out how to provoke the login failure): I restart the server and am able to login to the site. I log in and log out several times, everything is fine. I go to a non-existing page and get a server error. I log out and try to log back in, and I can't, just get redirected back to the login page. Case 3 (I can't provoke the login failure with Debug set to True): 1. I restart the server and am able to login to the site. 2. I log in and log out several times, everything is fine. 3. I go to a non-existing page and get a traceback. 4. I log out and log back in, everything works. 5. I wait and play around with it and can't get the login to fail while in Debug mode. Please help!
I can't login to my Django app when debug is set to False
0.039979
0
0
1,621
2,643,721
2010-04-15T08:23:00.000
0
0
0
0
python,django,apache,login,debugging
6,030,163
5
false
1
0
Make sure the urls.py file imports everything from django.conf.urls.defaults. You may have explicitly imported certain methods such as patterns and include (as I did to combat PyDev's 'wild import' warning messages). As a result, crucial statements that assign Django's default handlers to 404 and 500 HTTP error codes will be omitted. This is obviously undesired and leads to the odd behavior described in the question.
4
2
0
Short Story: I get locked out of my Django app when Debug is set to False. Long story: Case 1 (the first time it happened): I enter my login info, but It just redirects to the login page. I restart the server, try to login, and it works fine, I get in. a few hours later I come back, log out, try to log back in and I can't. It just redirects to the login page. Case 2 (I figure out how to provoke the login failure): I restart the server and am able to login to the site. I log in and log out several times, everything is fine. I go to a non-existing page and get a server error. I log out and try to log back in, and I can't, just get redirected back to the login page. Case 3 (I can't provoke the login failure with Debug set to True): 1. I restart the server and am able to login to the site. 2. I log in and log out several times, everything is fine. 3. I go to a non-existing page and get a traceback. 4. I log out and log back in, everything works. 5. I wait and play around with it and can't get the login to fail while in Debug mode. Please help!
I can't login to my Django app when debug is set to False
0
0
0
1,621
2,643,721
2010-04-15T08:23:00.000
1
0
0
0
python,django,apache,login,debugging
57,435,530
5
false
1
0
My problem was if I set SESSION_COOKIE_SECURE = True then I can't login in http mode. I had to change it to SESSION_COOKIE_SECURE = False Maybe you had this too?
4
2
0
Short Story: I get locked out of my Django app when Debug is set to False. Long story: Case 1 (the first time it happened): I enter my login info, but It just redirects to the login page. I restart the server, try to login, and it works fine, I get in. a few hours later I come back, log out, try to log back in and I can't. It just redirects to the login page. Case 2 (I figure out how to provoke the login failure): I restart the server and am able to login to the site. I log in and log out several times, everything is fine. I go to a non-existing page and get a server error. I log out and try to log back in, and I can't, just get redirected back to the login page. Case 3 (I can't provoke the login failure with Debug set to True): 1. I restart the server and am able to login to the site. 2. I log in and log out several times, everything is fine. 3. I go to a non-existing page and get a traceback. 4. I log out and log back in, everything works. 5. I wait and play around with it and can't get the login to fail while in Debug mode. Please help!
I can't login to my Django app when debug is set to False
0.039979
0
0
1,621
2,644,221
2010-04-15T09:47:00.000
3
0
1
0
python,list,tuples
2,645,203
6
false
0
0
[[int(i) for i in x.strip(" []").split(",")] for x in s.strip('[]').split("],")] a list comprehension in a list comprehension... but that will melt your brain
1
12
0
If a user types in [[0,0,0], [0,0,1], [1,1,0]] and press enter, the program should convert this string to several lists; one list holding [0][0][0], other for [0][0][1], and the last list for [1][1][0] Does python have a good way to handle this?
How can I convert this string to list of lists?
0.099668
0
0
24,352
2,645,749
2010-04-15T13:41:00.000
7
0
1
0
python,typechecking
2,646,481
4
false
0
0
I'd like a way to make sure a is a list, before looping through Document the function.
1
23
0
What is the easiest way to check if something is a list? A method doSomething has the parameters a and b. In the method, it will loop through the list a and do something. I'd like a way to make sure a is a list, before looping through - thus avoiding an error or the unfortunate circumstance of passing in a string then getting back a letter from each loop. This question must have been asked before - however my googles failed me. Cheers.
Check if something is a list
1
0
0
20,048
2,646,983
2010-04-15T16:07:00.000
2
0
0
0
python,proxy,tcp,sockets,socks
2,714,593
3
false
0
0
It is pretty simple - after you send the HTTP request: CONNECT example.com:1234 HTTP/1.0\r\nHost: example.com:1234\r\n<additional headers incl. authentication>\r\n\r\n, the server responds with HTTP/1.0 200 Connection established\r\n\r\n and then (after the double line ends) you can communicate just as you would communicate with example.com port 1234 without the proxy (as I understand you already have the client-server communication part done).
1
3
0
I am little stumped: I have a simple messenger client program (pure python, sockets), and I wanted to add proxy support (http/s, socks), however I am a little confused on how to go about it. I am assuming that the connection on the socket level will be done to the proxy server, at which point the headers should contain a CONNECT + destination IP (of the chat server) and authentication, (if proxy requires so), however the rest is a little beyond me. How is the subsequent connection handled, specifically the reading/writing, etc... Are there any guides on proxy support implementation for socket based (tcp) programming in Python? Thank you
Python, implementing proxy support for a socket based application (not urllib2)
0.132549
0
1
2,236
2,647,088
2010-04-15T16:20:00.000
1
1
1
0
python,python-import
2,647,367
3
false
0
0
In absence of more information, I would say you have a circular import that you aren't working around. The simplest, most obvious fix is to not put anything in mydir/__init__.py that you want to use from any module inside mydir. So, move your get_hash function to another module inside the mydir package, and import that module where you need it.
2
2
0
I've done what I shouldn't have done and written 4 modules (6 hours or so) without running any tests along the way. I have a method inside of /mydir/__init__.py called get_hash(), and a class inside of /mydir/utils.py called SpamClass. /mydir/utils.py imports get_hash() from /mydir/__init__. /mydir/__init__.py imports SpamClass from /mydir/utils.py. Both the class and the method work fine on their own but for some reason if I try to import /mydir/, I get an import error saying "Cannot import name get_hash" from /mydir/__init__.py. The only stack trace is the line saying that __init__.py imported SpamClass. The next line is where the error occurs in in SpamClass when trying to import get_hash. Why is this?
Python - import error
0.066568
0
0
493
2,647,088
2010-04-15T16:20:00.000
2
1
1
0
python,python-import
2,647,459
3
false
0
0
To add to what the others have said, another good approach to avoiding circular import problems is to avoid from module import stuff. If you just do standard import module at the top of each script, and write module.stuff in your functions, then by the time those functions run, the import will have finished and the module members will all be available. You then also don't have to worry about situations where some modules can update/change one of their members (or have it monkey-patched by a naughty third party). If you'd imported from the module, you'd still have your old, out-of-date copy of the member. Personally, I only use from-import for simple, dependency-free members that I'm likely to refer to a lot: in particular, symbolic constants.
2
2
0
I've done what I shouldn't have done and written 4 modules (6 hours or so) without running any tests along the way. I have a method inside of /mydir/__init__.py called get_hash(), and a class inside of /mydir/utils.py called SpamClass. /mydir/utils.py imports get_hash() from /mydir/__init__. /mydir/__init__.py imports SpamClass from /mydir/utils.py. Both the class and the method work fine on their own but for some reason if I try to import /mydir/, I get an import error saying "Cannot import name get_hash" from /mydir/__init__.py. The only stack trace is the line saying that __init__.py imported SpamClass. The next line is where the error occurs in in SpamClass when trying to import get_hash. Why is this?
Python - import error
0.132549
0
0
493
2,647,105
2010-04-15T16:23:00.000
14
0
1
0
python,ctypes,cython
2,648,095
4
true
0
0
Ignore everyone elses' answer for now. The first thing you should learn to use is the profiler. Python comes with a profile/cProfile; you should learn how to read the results and analyze where the real bottlenecks is. The goal of optimization is three-fold: reduce the time spent on each call, reduce the number of calls to be made, and reduce memory usage to reduce disk thrashing. The first goal is relatively easy. The profiler will show you the most time-consuming functions and you can go straight to that function to optimize it. The second and third goal is harder since this means you need to change the algorithm to reduce the need to make so much calls. Find the functions that have high number of calls and try to find ways to reduce the need to call them. Utilize the built-in collections, they're very well optimized. If you're doing a lot of number and array processing, you should take a look at pandas, Numpy/Scipy, gmpy third party modules; they're well optimised C libraries for processing arrays/tabular data. Another thing you want to try is PyPy. PyPy can JIT recompile and do much more advanced optimisation than CPython, and it'll work without the need to change your python code. Though well optimised code targeting CPython can look quite different from well optimised code targeting PyPy. Next to try is Cython. Cython is a slightly different language than Python, in fact Cython is actually best described as C with typed Python-like syntax. For parts of your code that is in very tight loops that you can no longer optimize using any other ways, you may want to rewrite it as C extension. Python has a very good support for extending with C. In PyPy, the best way to extend PyPy is with cffi.
4
8
0
I'm having a lot of fun learning Python by writing a genetic programming type of application. I've had some great advice from Torsten Marek, Paul Hankin and Alex Martelli on this site. The program has 4 main functions: generate (randomly) an expression tree. evaluate the fitness of the tree crossbreed mutate As all of generate, crossbreed and mutate call 'evaluate the fitness'. it is the busiest function and is the primary bottleneck speedwise. As is the nature of genetic algorithms, it has to search an immense solution space so the faster the better. I want to speed up each of these functions. I'll start with the fitness evaluator. My question is what is the best way to do this. I've been looking into cython, ctypes and 'linking and embedding'. They are all new to me and quite beyond me at the moment but I look forward to learning one and eventually all of them. The 'fitness function' needs to compare the value of the expression tree to the value of the target expression. So it will consist of a postfix evaluator which will read the tree in a postfix order. I have all the code in python. I need advice on which I should learn and use now: cython, ctypes or linking and embedding. Thank you.
I need to speed up a function. Should I use cython, ctypes, or something else?
1.2
0
0
2,763
2,647,105
2010-04-15T16:23:00.000
0
0
1
0
python,ctypes,cython
2,649,773
4
false
0
0
Try to work your fitness function so that it will support memoization. This will replace all calls that are duplicates of previous calls with a quick dict lookup.
4
8
0
I'm having a lot of fun learning Python by writing a genetic programming type of application. I've had some great advice from Torsten Marek, Paul Hankin and Alex Martelli on this site. The program has 4 main functions: generate (randomly) an expression tree. evaluate the fitness of the tree crossbreed mutate As all of generate, crossbreed and mutate call 'evaluate the fitness'. it is the busiest function and is the primary bottleneck speedwise. As is the nature of genetic algorithms, it has to search an immense solution space so the faster the better. I want to speed up each of these functions. I'll start with the fitness evaluator. My question is what is the best way to do this. I've been looking into cython, ctypes and 'linking and embedding'. They are all new to me and quite beyond me at the moment but I look forward to learning one and eventually all of them. The 'fitness function' needs to compare the value of the expression tree to the value of the target expression. So it will consist of a postfix evaluator which will read the tree in a postfix order. I have all the code in python. I need advice on which I should learn and use now: cython, ctypes or linking and embedding. Thank you.
I need to speed up a function. Should I use cython, ctypes, or something else?
0
0
0
2,763
2,647,105
2010-04-15T16:23:00.000
0
0
1
0
python,ctypes,cython
2,647,189
4
false
0
0
Another great option is boost::python which lets you easily wrap C or C++. Of these possibilities though, since you have python code already written, cython is probably a good thing to try first. Perhaps you won't have to rewrite any code to get a speedup.
4
8
0
I'm having a lot of fun learning Python by writing a genetic programming type of application. I've had some great advice from Torsten Marek, Paul Hankin and Alex Martelli on this site. The program has 4 main functions: generate (randomly) an expression tree. evaluate the fitness of the tree crossbreed mutate As all of generate, crossbreed and mutate call 'evaluate the fitness'. it is the busiest function and is the primary bottleneck speedwise. As is the nature of genetic algorithms, it has to search an immense solution space so the faster the better. I want to speed up each of these functions. I'll start with the fitness evaluator. My question is what is the best way to do this. I've been looking into cython, ctypes and 'linking and embedding'. They are all new to me and quite beyond me at the moment but I look forward to learning one and eventually all of them. The 'fitness function' needs to compare the value of the expression tree to the value of the target expression. So it will consist of a postfix evaluator which will read the tree in a postfix order. I have all the code in python. I need advice on which I should learn and use now: cython, ctypes or linking and embedding. Thank you.
I need to speed up a function. Should I use cython, ctypes, or something else?
0
0
0
2,763
2,647,105
2010-04-15T16:23:00.000
3
0
1
0
python,ctypes,cython
2,647,245
4
false
0
0
Cython is the quickest to get the job done, either by writing your algorithm directly in Cython, or by writing it in C and bind it to python with Cython. My advice: learn Cython.
4
8
0
I'm having a lot of fun learning Python by writing a genetic programming type of application. I've had some great advice from Torsten Marek, Paul Hankin and Alex Martelli on this site. The program has 4 main functions: generate (randomly) an expression tree. evaluate the fitness of the tree crossbreed mutate As all of generate, crossbreed and mutate call 'evaluate the fitness'. it is the busiest function and is the primary bottleneck speedwise. As is the nature of genetic algorithms, it has to search an immense solution space so the faster the better. I want to speed up each of these functions. I'll start with the fitness evaluator. My question is what is the best way to do this. I've been looking into cython, ctypes and 'linking and embedding'. They are all new to me and quite beyond me at the moment but I look forward to learning one and eventually all of them. The 'fitness function' needs to compare the value of the expression tree to the value of the target expression. So it will consist of a postfix evaluator which will read the tree in a postfix order. I have all the code in python. I need advice on which I should learn and use now: cython, ctypes or linking and embedding. Thank you.
I need to speed up a function. Should I use cython, ctypes, or something else?
0.148885
0
0
2,763
2,647,288
2010-04-15T16:48:00.000
4
0
1
0
python
2,647,445
6
false
0
0
Magic that works but not always. For example, when metaclasses are abused to create a DSL. Such DSL could be suitable for most tasks but breaks horribly on a complex (unexpected by author) one.
3
4
0
My impression of Python from the short time I've been developing with it is that it's incredible powerful and flexible, but I can't help but feel like "with great power comes great responsibility." So while I've read numerous blog posts about simple and elegant Python snippets that solve a problems, I wonder if there are design patterns or abuses of Python language features that, once built into an application or library, cause the code to be incredibly brittle and near impossible to refactor. So the question is basically what are the most frustrating, but somewhat common, Python "hacks" or language feature abuses that someone can introduce that will cause nightmares for future maintainers of that code?
What are the most frustrating Python hacks to unwind, rewrite, etc.?
0.132549
0
0
1,012
2,647,288
2010-04-15T16:48:00.000
4
0
1
0
python
2,647,563
6
false
0
0
Using eval or exec on user input may be the most common abuse of Python features.
3
4
0
My impression of Python from the short time I've been developing with it is that it's incredible powerful and flexible, but I can't help but feel like "with great power comes great responsibility." So while I've read numerous blog posts about simple and elegant Python snippets that solve a problems, I wonder if there are design patterns or abuses of Python language features that, once built into an application or library, cause the code to be incredibly brittle and near impossible to refactor. So the question is basically what are the most frustrating, but somewhat common, Python "hacks" or language feature abuses that someone can introduce that will cause nightmares for future maintainers of that code?
What are the most frustrating Python hacks to unwind, rewrite, etc.?
0.132549
0
0
1,012
2,647,288
2010-04-15T16:48:00.000
4
0
1
0
python
2,651,847
6
true
0
0
Excessive usage of from module import *. Having a lot of such imports at the module you don't know where each variable came from and have to look though all imported modules. Searching doesn't help much in this case.
3
4
0
My impression of Python from the short time I've been developing with it is that it's incredible powerful and flexible, but I can't help but feel like "with great power comes great responsibility." So while I've read numerous blog posts about simple and elegant Python snippets that solve a problems, I wonder if there are design patterns or abuses of Python language features that, once built into an application or library, cause the code to be incredibly brittle and near impossible to refactor. So the question is basically what are the most frustrating, but somewhat common, Python "hacks" or language feature abuses that someone can introduce that will cause nightmares for future maintainers of that code?
What are the most frustrating Python hacks to unwind, rewrite, etc.?
1.2
0
0
1,012
2,647,723
2010-04-15T17:48:00.000
16
0
0
0
python,string,urllib2
35,367,453
4
false
1
0
In python3, it should be changed to urllib.request.openurl('http://www.example.com/').read().decode('utf-8').
1
7
0
I'm using urllib2 to open a url. Now I need the html file as a string. How do I do this?
urllib2 to string
1
0
1
17,378
2,647,790
2010-04-15T18:00:00.000
7
1
1
0
python,unit-testing,exception-handling,runtime-error,code-coverage
2,648,113
4
false
0
0
The problem here is that malformed external input crashed your program. The solution is to exhaustively unit test possible input scenarios at the boundaries of your code. You say your unit tests are 'extensive', but you clearly hadn't tested for this possibility. Code coverage is a useful tool, but it's important to remember that covering code is not the same as thoroughly testing it. Thorough testing is a combination of covering usage scenarios as well as lines of code. The methodology I use is to trust internal callers, but never to trust external callers or input. So I explicitly don't unit test for the empty list case in any code beyond the first function that receives the external input. But that input function should be exhaustively covered. In this case I think the library's exception is reasonable behaviour - it makes no sense to ask for the min of an empty list. The library can't legitimately set a value such as 0 for you, since you may be dealing with negative numbers, for example. I think the empty list should never have reached the code that asks for the min - it should have been identified at input, and either raised an exception there, or set it to 0 if that works for you, or whatever else it is that does work for you.
2
4
0
I recently came across a simple but nasty bug. I had a list and I wanted to find the smallest member in it. I used Python's built-in min(). Everything worked great until in some strange scenario the list was empty (due to strange user input I could not have anticipated). My application crashed with a ValueError (BTW - not documented in the official docs). I have very extensive unit tests and I regularly check coverage to avoid surprises like this. I also use Pylint (everything is integrated in PyDev) and I never ignore warnings, yet I failed to catch this bug before my users did. Is there anything I can change in my methodology to avoid these kind of runtime errors? (which would have been caught at compile time in Java / C#?). I'm looking for something more than wrapping my code with a big try-except. What else can I do? How many other build in Python functions are hiding nasty surprises like this???
Python Pre-testing for exceptions when coverage fails
1
0
0
784
2,647,790
2010-04-15T18:00:00.000
4
1
1
0
python,unit-testing,exception-handling,runtime-error,code-coverage
2,647,972
4
false
0
0
Even in Java/C#, a class of exceptions the RuntimeError are unchecked and will not be detected by the compiler (that's why they're called RuntimeError not CompileError). In python, certain exceptions such as KeyboardInterrupt are particularly hairy since it can be raised practically at any arbitrary point in the program. I'm looking for something more than wrapping my code with a big try-except. Anything but that please. It is much better to let exceptions get to user and halt the program rather than letting error pass around silently (Zen of Python). Unlike Java, Python does not require all Exceptions to be caught because requiring all Exceptions to be caught makes it too easy for programmers to ignore the Exception (by writing blank exception handler). Just relax, let the error halt; let the user report it to you, so you can fix it. The other alternative is you stepping into a debugger for forty-two hours because customer's data is getting corrupted everywhere due to a blank mandatory exception handler. So, what you should change in your methodology is thinking that exception is bad; they're not pretty, but they're better than the alternatives.
2
4
0
I recently came across a simple but nasty bug. I had a list and I wanted to find the smallest member in it. I used Python's built-in min(). Everything worked great until in some strange scenario the list was empty (due to strange user input I could not have anticipated). My application crashed with a ValueError (BTW - not documented in the official docs). I have very extensive unit tests and I regularly check coverage to avoid surprises like this. I also use Pylint (everything is integrated in PyDev) and I never ignore warnings, yet I failed to catch this bug before my users did. Is there anything I can change in my methodology to avoid these kind of runtime errors? (which would have been caught at compile time in Java / C#?). I'm looking for something more than wrapping my code with a big try-except. What else can I do? How many other build in Python functions are hiding nasty surprises like this???
Python Pre-testing for exceptions when coverage fails
0.197375
0
0
784
2,647,862
2010-04-15T18:11:00.000
2
0
1
0
python,import
2,647,882
3
false
0
0
Look at the foolib.__file__.
1
5
0
I'm trying to modify a python library that I downloaded and am using. But the changes I'm making aren't doing anything. So I suspect that python is importing a different copy of this library from somewhere else on the filesystem. So... When I run import foolib in python, how can I tell where on the filesystem it's getting that library from?
How can I tell what directory an imported library comes from in python?
0.132549
0
0
298
2,648,121
2010-04-15T18:53:00.000
2
0
1
0
python,computer-science
2,648,174
5
false
0
0
This is the traditional meaning of "function" in the mathematical sense. What you're describing, more than anything else, should be called a function. To distinguish it from a function that has side effects, you can also call it a "pure function" — this means the function will always return the same result given the same argument and won't affect anything else.
5
3
0
I was wondering what language to use when talking about a function that takes in a specific object, acts on it and returns something else. Clearly they're functions, but I was wondering if there's a more specific term. A couple examples of Python built-in functions that fit this spec are: 'len', 'dir', 'vars' I thought it was 'predicate', but apparently that's specific to functions that return a boolean value.
What are 'len', 'dir', 'vars' named?
0.07983
0
0
246
2,648,121
2010-04-15T18:53:00.000
2
0
1
0
python,computer-science
2,648,167
5
false
0
0
They're unary functions, since they have a single parameter, but they're nothing more special than that.
5
3
0
I was wondering what language to use when talking about a function that takes in a specific object, acts on it and returns something else. Clearly they're functions, but I was wondering if there's a more specific term. A couple examples of Python built-in functions that fit this spec are: 'len', 'dir', 'vars' I thought it was 'predicate', but apparently that's specific to functions that return a boolean value.
What are 'len', 'dir', 'vars' named?
0.07983
0
0
246
2,648,121
2010-04-15T18:53:00.000
1
0
1
0
python,computer-science
2,648,158
5
false
0
0
I'd call them intrinsic functions.
5
3
0
I was wondering what language to use when talking about a function that takes in a specific object, acts on it and returns something else. Clearly they're functions, but I was wondering if there's a more specific term. A couple examples of Python built-in functions that fit this spec are: 'len', 'dir', 'vars' I thought it was 'predicate', but apparently that's specific to functions that return a boolean value.
What are 'len', 'dir', 'vars' named?
0.039979
0
0
246
2,648,121
2010-04-15T18:53:00.000
5
0
1
0
python,computer-science
2,648,144
5
false
0
0
Call them functions. That's something everyone will understand. You could also call them subroutines, methods, or procedures, but sometimes those have specific and different meanings in different languages. But "Function" is something most people will understand, no matter then language (even though there may be slight differences from one programming language to the next).
5
3
0
I was wondering what language to use when talking about a function that takes in a specific object, acts on it and returns something else. Clearly they're functions, but I was wondering if there's a more specific term. A couple examples of Python built-in functions that fit this spec are: 'len', 'dir', 'vars' I thought it was 'predicate', but apparently that's specific to functions that return a boolean value.
What are 'len', 'dir', 'vars' named?
0.197375
0
0
246
2,648,121
2010-04-15T18:53:00.000
6
0
1
0
python,computer-science
2,648,135
5
true
0
0
There isn't really a generic term for these kinds of functions, although Python internally uses 'inquiry' for this kind of function. I rarely see them described as anything other than just plain 'function', though.
5
3
0
I was wondering what language to use when talking about a function that takes in a specific object, acts on it and returns something else. Clearly they're functions, but I was wondering if there's a more specific term. A couple examples of Python built-in functions that fit this spec are: 'len', 'dir', 'vars' I thought it was 'predicate', but apparently that's specific to functions that return a boolean value.
What are 'len', 'dir', 'vars' named?
1.2
0
0
246
2,649,882
2010-04-16T00:34:00.000
3
0
1
0
python,user-interface
2,649,957
5
false
0
1
Yes, you can use PyQt, or PySide (another Qt binding), or wxPython. They all support native look & feel. There's also PyGTK, but gtk apps don't to look so native .. I personally prefer Qt, so I'd suggest PyQt. If you have issues with the GPL, then you can use PySide (LGPL).
1
16
0
I haven't gotten far enough into Python to make GUIs yet, so I thought I'd ask here. Can a python app be made with the windows default style GUI, or will it have its own style? The only screenshots I've seen of a python app running with a GUI had this ugly win95 look to it.
Can a native-looking GUI be made with Python
0.119427
0
0
6,722
2,650,014
2010-04-16T01:21:00.000
6
0
0
1
python,database,google-app-engine,global
2,650,039
1
true
1
0
The datastore is the only place you can have guaranteed-persistent data that are also modifiable. So you can have a single large object, or several smaller ones (with a name attribute and others), depending on your desired access patterns -- but live in the datastore it must. You can use memcache for faster cache that usually persists across queries, but any memcache entry could go away any time, so you'll always need it to be backed by the datastore (in particular, any change must go to the datastore, not just to memcache).
1
1
0
I'm looking for a way to keep the equivalent of persistent global variables in app engine (python). What I'm doing is creating a global kind that I initialize once (i.e. when I reset all my database objects when I'm testing). I have things in there like global counters, or the next id to assign certain kinds I create. Is this a decent way to do this sort of thing or is there generally another approach that is used?
google app engine persistent globals
1.2
0
0
595
2,650,073
2010-04-16T01:41:00.000
2
1
0
0
python,c++,encryption,cryptography
2,650,311
1
false
0
1
The C++ libraries seem to have dependencies to hundreds of files. I don't know much about Python, but that is absolutely normal for C++. I'd recommend Crypto++ -- it's a great easy to use library, and it's public domain, meaning you won't have any license problems with it. EDIT: Keep in mind a large library with lots of code does not mean that you're going to pay in terms of object code. If there are functions you don't use (Crypto++ supports hundreds of algorithms) they won't be compiled into the resulting binary.
1
1
0
I'm looking to do some basic encryption of server messages which would be encrypted with C++ and decrypted using Python server side. I was wondering if anyone knew if there were good solutions that were simpler or more lightweight than Keyczar. I see that supports both C++ and python, but would using Crypto++ and PyCrypto be simpler for a newbie that just wants to get something up and running for the time being? Or should I use Keyczar for python and Crypto++ for the C++ end? The C++ libraries seem to have dependencies to hundreds of files.
Lightweight cryptography toolkit(s) for C++ and Python
0.379949
0
0
942
2,650,106
2010-04-16T01:52:00.000
1
0
0
0
python,django,django-models,django-admin
2,656,270
4
false
1
0
I like the idea of not making users remember a username, but I think a better solution to that is to have their email address be their user name. Is it fair for you to assume in your specific application that no two users will have the same first and last name? If that's not a fair assumption, how will your system handle that?
2
1
0
i want to authenticate users using firstname and lastname This is the code i am using user = auth.authenticate(first_name=firstname,last_name=lastname,password=password) it keep coming up with NoneType: None i have checked the firstname and lastname plus password seen to be correct? what i am doing wrong? thanks
Django, How authenticate user with first name and last name?
0.049958
0
0
1,594
2,650,106
2010-04-16T01:52:00.000
2
0
0
0
python,django,django-models,django-admin
2,650,166
4
false
1
0
Building a little from @T. Stone's idea. Why not have them register with their First and Last name and you just concatenate them together and use that as their username?. And everytime you have them login you setup your view to combine the two fields again and use that string. You won't be able to use some of the auto forms they can produce for you but that's not a big deal. I'd just combine the two strings, lowercase them and slap that as the username and do the same for every login instance.
2
1
0
i want to authenticate users using firstname and lastname This is the code i am using user = auth.authenticate(first_name=firstname,last_name=lastname,password=password) it keep coming up with NoneType: None i have checked the firstname and lastname plus password seen to be correct? what i am doing wrong? thanks
Django, How authenticate user with first name and last name?
0.099668
0
0
1,594
2,650,189
2010-04-16T02:25:00.000
0
0
0
0
python,django,authentication
2,650,293
3
false
1
0
To T. Stone's point, end users are notorious for passing links around -- ESPECIALLY those in an intraweb environment. Having something that authenticated the user automatically means that I can almost guarantee that you're going to have at least one person logged in as somebody else. There are better ways, of course, to refresh a user's session from Cookie information, so you at least have a decent idea that they're a valid user attached to a valid browser and can feel SOMEwhat safer in that they aren't likely to hand their laptops about like they might with a link, but yes... to reiterate, what you're trying to do is a VERY bad idea if your app has more than 1 user.
1
3
0
In my web app I would like to be able to email self-authenticating links to users. These links will contain a unique token (uuid). When they click the link the token being present in the query string will be enough to authenticate them and they won't have to enter their username and password. What's the best way to do this?
Self Authenticating Links in Django
0
0
0
1,274
2,650,499
2010-04-16T03:57:00.000
0
0
0
1
python,mysql,google-app-engine,bulk-load
2,662,880
3
false
1
0
If you're using Pentaho BI Server as your data source, why don't you consider using Pentaho Data Integration (ETL tool) to move the data over? At the very least PDI automate any movement of data between your data source and any AppEngine bulk loader tool (it can easily trigger any app with a shell step).
1
0
0
I'm from Brazil and study at FATEC (college located in Brazil). I'm trying to learn about AppEngine. Now, I'm trying to load a large database from MySQL to AppEngine to perform some queries, but I don't know how i can do it. I did some testing with CSV files,but is there any way to perform the direct import from MySQL? This database is from Pentaho BI Server (www.pentaho.com). Thank you for your attention. Regards, Daniel Naito
MySQL to AppEngine
0
1
0
1,278
2,650,591
2010-04-16T04:21:00.000
0
0
0
0
python,pygtk
2,788,540
3
false
0
1
gtk.TextView is "rich", in that it can display all types of formatting and even embedded widgets. If you want the functionality of editing rich text, you will have to write something yourself, though others have tried in applications like BloGTK. From which you could steal codes.
1
1
0
I would like to include a rich text editor in a pygtk drawing area for an application i am developing. The editor ( a small resizable widget ) should be able to move around the drawing area like a rectangle. I am not sure how to start as I am pretty new to PyGTK. thank you !
Py GTK Drawing area and Rich Text Editor
0
0
0
2,291
2,651,466
2010-04-16T07:58:00.000
2
1
1
0
python
2,651,534
2
false
0
0
Look for the subprocess module. It is the recommended way to invoke processes from within Python. The os.system function is a viable alternative sometimes, if your needs are very simple (no pipes, simple arguments, etc.)
2
0
0
i have this encryption algorithm written in C++ , but the values that has to be encrypted are being taken input and stored in a file by a python program . Thus how can i call this c++ program from python?
how to call a c++ file from python without using any of the spam bindings?
0.197375
0
0
83
2,651,466
2010-04-16T07:58:00.000
0
1
1
0
python
2,651,490
2
false
0
0
The os.system function will invoke an arbitrary command-line from python.
2
0
0
i have this encryption algorithm written in C++ , but the values that has to be encrypted are being taken input and stored in a file by a python program . Thus how can i call this c++ program from python?
how to call a c++ file from python without using any of the spam bindings?
0
0
0
83
2,652,146
2010-04-16T10:26:00.000
5
1
0
0
python,virtualbox,xpcom
2,655,522
3
false
0
0
I would generally recommend against either one. If you need to use virtualization programmatically, take a look at libvirt, which gives you cross platform and cross hypervisor support; which lets you do kvm/xen/vz/vmware later on. That said, the SOAP api is using two extra abstraction layers (the client and server side of the HTTP transaction), which is pretty clearly then just calling the XPCOM interface. If you need local host only support, use XPCOM. The extra indirection of libvirt/SOAP doesn't help you. If you need to access virtualbox on a various hosts across multiple client machines, use SOAP or libvirt If you want cross platform support, or to run your code on Linux, use libvirt.
1
9
0
what is the advantage of using a python virtualbox API instead of using XPCOM?
What is the advantage of using Python Virtualbox API?
0.321513
0
1
14,030
2,652,394
2010-04-16T11:09:00.000
0
0
0
0
python,google-app-engine,google-cloud-datastore
2,656,720
2
false
1
0
If it's really just a list of tuples / two "columns", could you just use an alternating list and a ListProperty? This would be fine if the data had a consistent dimension, was small, and didn't require indexing. e.g. To encode the example you gave in a list do: # i forget if mixed types are allowed, but you get the idea. ["xyz", 123, "abc", 456, "hij", 678, "rer", 838]
1
2
0
I need to store some data that looks a little like this: xyz 123 abc 456 hij 678 rer 838 Now I would just store it as a traditional string and integer model, and put in the datastore. But the data changes regularly, and is ONLY relevant when looked at as a COLLECTION. So it needs to be store as either a list of lists, or a list of objects, both of which can't really be done without pickling as far as I know. Can anyone help? Even storing it as a text file may work :S Edit: I was a litle vague on details it seems. I am sampling some data from an external source (scraping via BeautifulSoup/http2lib if it matters). This data then needs to be stored, as a whole, since it will be plotted on a graph. The data changes (but not often - perhaps once a week). Since the dataset is so simple (literally what you see above, 1 string field, and 1 integer) I figured it's easier to store them as a list of lists, then actually store them in a model. I have a feeling I have skipped over an even easier solution by concentrating too much on the fact the data needs to be stored together as one large lump. I will be storing 500+ of these bits of data as a group, at once.
Storing a list of objects in GAE
0
0
0
296
2,653,079
2010-04-16T12:59:00.000
1
0
0
0
python,file,urllib,file-type
2,653,447
3
false
0
0
I suspect you may be optimising prematurely here. Most modern systems will cache files in memory for a significant period of time before they flush them to disk, so if you write the data to a temporary file, read it back in, then close and delete the file you may find that there's no significant disc traffic (unless it really is 100MB). You might want to look at using tempfile.TemporaryFile() which creates a temporary file that is automatically deleted when closed, or else tempfile.SpooledTemporaryFile() which explicitly holds it all in memory until it exceeds a particular size.
1
2
0
PdfFileReader reads the content from a pdf file to create an object. I am querying the pdf from a cdn via urllib.urlopen(), this provides me a file like object, which has no seek. PdfFileReader, however uses seek. What is the simple way to create a PdfFileReader object from a pdf downloaded via url. Now, what can I do to avoid writing to disk and reading it again via file(). Thanks in advance.
Inexpensive ways to add seek to a filetype object
0.066568
0
1
275
2,654,425
2010-04-16T16:02:00.000
2
1
1
0
python,ruby,lambda,restriction
3,209,231
5
false
0
0
Instead of f=lambda s:pass you can do f=lambda s:None.
2
6
0
I was going over some pages from WikiVS, that I quote from: because lambdas in Python are restricted to expressions and cannot contain statements I would like to know what would be a good example (or more) where this restriction would be, preferably compared to the Ruby language. Thank you for your answers, comments and feedback!
Restrictons of Python compared to Ruby: lambda's
0.07983
0
0
2,261
2,654,425
2010-04-16T16:02:00.000
1
1
1
0
python,ruby,lambda,restriction
2,654,789
5
false
0
0
lambda is simply a shortcut way in Python to define a function that returns a simple expression. This isn't a restriction in any meaningful way. If you need more than a single expression then just use a function: there is nothing you can do with a lambda that you cannot do with a function. The only disadvantages to using a function instead of a lambda are that the function has to be defined on 1 or more separate lines (so you may lose some locality compared to the lambda), and you have to invent a name for the function (but if you can't think of one then f generally works). All the other reasons people think they have to use a lambda (such as accessing nested variables or generating lots of lambdas with separate default arguments) will work just as well with a function. The big advantage of using a named function is of course that when it goes wrong you get a meaningful stack trace. I had that bite me yesterday when I got a stack trace involving a lambda and no context about which lambda it was.
2
6
0
I was going over some pages from WikiVS, that I quote from: because lambdas in Python are restricted to expressions and cannot contain statements I would like to know what would be a good example (or more) where this restriction would be, preferably compared to the Ruby language. Thank you for your answers, comments and feedback!
Restrictons of Python compared to Ruby: lambda's
0.039979
0
0
2,261
2,654,484
2010-04-16T16:11:00.000
1
0
1
0
python,function,variables,global-variables
2,654,582
2
true
0
0
If you want to share data between functions then create a class and turn the functions into methods on the class.
2
0
0
in python, how can i access the variables of one function into another function, is it possible, i tried the global variable method but that doesn't work for me. can someone help me, how to access the variables from one function to another function.
access variables of other functions
1.2
0
0
1,692
2,654,484
2010-04-16T16:11:00.000
0
0
1
0
python,function,variables,global-variables
2,654,647
2
false
0
0
Don't try to do this. Explicit is better than implicit - if your function needs access to certain variables, pass them in. If it needs to change a value in the calling function, return the new value.
2
0
0
in python, how can i access the variables of one function into another function, is it possible, i tried the global variable method but that doesn't work for me. can someone help me, how to access the variables from one function to another function.
access variables of other functions
0
0
0
1,692
2,654,689
2010-04-16T16:43:00.000
0
0
0
0
python,django,profiles
2,657,984
4
false
1
0
Thank you all for your answers! I know that django dev documentation mentions user profiles, but does it very briefly (roughly few lines) and links to djangobook containing information about user profiles, but... to its first version, covering django 0.96. The second version of djangobook, covering django 1.0 (that is way closer to 1.2 than 0.96) no longer has that information anywhere, what makes me highly confused - has anything changed? Is there other, better, more secure way to handle users and their profiles? Therefore this question asked.
1
3
0
I am writing simple site that requires users and profiles to be handled. The first initial thought is to use django's build in user handling, but then the user model is too narrow and does not contain fields that I need. The documentation mentions user profiles, but user profiles section has been removed from djangobook covering django 1.0 (ideally, the solution should work with django 1.2), and the Internet is full of different solutions, not making the choice easier (like user model inheritance, user profiles and django signals, and so on). I would like to know, how to write this in good, modern, fast and secure way. Should I try to extend django builtin user model, or maybe should I create my own user model wide enough to keep all the information I need? Below you may find some specifications and expectations from the working solution: users should be able to register and authenticate every user should have profile (or model with all required fields) users dont need django builtin admin panel, but they need to edit their profiles/models via simple web form Please, let me know how do you solve those issues in your applications, and what is the best current way to handle users with django. Any links to articles/blogs or code examples are highly appreciated!
Django - how to write users and profiles handling in best way?
0
0
0
2,938
2,654,834
2010-04-16T17:04:00.000
4
1
1
0
python,stream
2,654,886
4
true
0
0
You said that your script "calls a bunch of functions" so I'm assuming that they're python functions accessible from your program. I'm also assuming you're using print to generate the output in all these functions. If that's the case, you can just replace sys.stdout with a StringIO.StringIO which will intercept all the stuff you're writing. Then you can finally call the .getValue method on your StringIO to get everything that has been sent to the output channel. This will also work for external programs using the subprocess module which write to sys.stdout. This is a cheap way. I'd recommend that you do your output using the logging module. You'll have much more control over how it does it's output and you can control it more easily as well.
1
7
0
I've got a python script that calls a bunch of functions, each of which writes output to stdout. Sometimes when I run it, I'd like to send the output in an e-mail (along with a generated file). I'd like to know how I can capture the output in memory so I can use the email module to build the e-mail. My ideas so far were: use a memory-mapped file (but it seems like I have to reserve space on disk for this, and I don't know how long the output will be) bypass all this and pipe the output to sendmail (but this may be difficult if I also want to attach the file)
Capturing stdout within the same process in Python
1.2
0
0
4,960
2,655,643
2010-04-16T19:32:00.000
0
0
1
1
python,readline,readlines,ungetc
2,878,464
6
false
0
0
The question was initially prompted by my need to build a lexical analyzer. getc() and ungetc() are useful at first (to get the read bugs out the way and to build the state machine) After the state machine is done, getc() and ungetc() become a liability as they take too long to read directly from storage. When the state machine was complete (debugged any IO problems, finalized the states), I optimized the lexical analyzer. Reading the source file in chunks (or pages) into memory and running the state machine on each page yields the best time result. I found that considerable time is saved if getc() and ungetc() are not used to read from the file directly.
1
2
0
Some file read (readlines()) functions in Python copy the file contents to memory (as a list) I need to process a file that's too large to be copied in memory and as such need to use a file pointer (to access the file one byte at a time) -- as in C getc(). The additional requirement I have is that I'd like to rewind the file pointer to previous bytes like in C ungetc(). Is there a way to do this in Python? Also, in Python, I can read one line at a time with readline() Is there a way to read the previous line going backward?
ungetc in Python
0
0
0
2,250
2,655,747
2010-04-16T19:52:00.000
0
0
0
0
python,mouseevent,rollover,vpython
2,718,009
3
false
0
1
scene.mouse.getclick will tell you where the mouse was when it was last clicked. This is different from scene.mouse.clicked which tells you if someone clicked. There is no correspoding way to see if someone had their mouse over a particular object. One thing you can do is use a while loop that continually checks scene.mouse.pick to see if it is the mouse is currently over an object of interest.
2
2
0
Is there something similar to scene.mouse.getclick in the visual module (VPython)? I need it for a rollover. Thanks in advance. EDIT: I need a function for doing something when the mouse moves inside a special area without clicking.
mouse rollover event in Python (VPython)
0
0
0
594
2,655,747
2010-04-16T19:52:00.000
1
0
0
0
python,mouseevent,rollover,vpython
2,726,099
3
true
0
1
As mentioned by mathmike, it would seem that you could use scene.mouse.pick to get the object that is currently under the mouse, and as for the 'scene-position', I think scene.mouse.pickpos is what you're looking for - if not, you should be able to calculate it from the global mouse position (through getEvent()). Otherwise, look at getting your information from the getEvent() function, and possibly writing an event loop for yourself.
2
2
0
Is there something similar to scene.mouse.getclick in the visual module (VPython)? I need it for a rollover. Thanks in advance. EDIT: I need a function for doing something when the mouse moves inside a special area without clicking.
mouse rollover event in Python (VPython)
1.2
0
0
594
2,657,036
2010-04-17T02:52:00.000
4
0
0
0
.net,python,user-interface,ironpython,pyqt
3,042,547
5
false
0
1
Per my play with both PyQt (as interface to Qt) and IronPython (as an interface to WinForms) the bag is mixed. Both are basically "bindings" for underlying platforms. PyQt is practically "autogenerated" from Qt's API and slightly more "mature" as a wrapper because of significant use on Linux. IronPython goes a little deeper and seems to "rebox" system objects with small unfilled gaps between cPython and .Net libs (gzip, zip, subprocess etc). In both cases, you need to look through Python into the toolkit and say to yourself if you like the toolkit. All python is doing is repackaging the toolkit's API to the objects. Again, forget about Python aspect. Look at the underlying toolkit API and think to yourself if you can live with that. I personally find the C++ nature of Qt's API too un-pythonic to be happy with it. C# and Python are so alike that if you remove curlies and type declaration from C# you would not know if it's C# or Python. As a result, for a Python programmer, C#-based .Net API, code and examples as provided in MSDN and elsewhere are instantly applicable with very minor tweaks. In the end, a more correct comparison would be between PyQt (Qt bindings for cPython) and Win32py (Windows ABI bindings for cPython). IronPython is almost a reinvention of same language on a different platform, with all the problems (lacking functionality) that comes with that.
5
8
0
I'm new in using Python. I would like to develop Windows GUI Application using Python. After some research, I found that I have 2 options:- IronPython + .NET Framework Python + PyQt May I know which one is better for Windows Application development? Which option has more features (e.g. database support, etc)? Other than the .NET support, is there any big difference between IronPython and Python? Which one is a better choice for me? Thank you. Patrick.L
"IronPython + .NET" vs "Python + PyQt". Which one is better for Windows App development?
0.158649
0
0
5,960
2,657,036
2010-04-17T02:52:00.000
5
0
0
0
.net,python,user-interface,ironpython,pyqt
2,668,271
5
false
0
1
I faced the same issue and have, with misgivings, decided to go with IronPython/C#/.Net. I liked Qt but got cold feet when it was sold to Nokia because I just wasn't sure Nokia's goals in owning Qt were consistent with my needs for a windows UI. That said, Nokia has made some positive moves by combining separate platform licenses into a single license and dropping GPL licensing in favor or LGPL. Technically, Qt is well designed but relies heavily on hard to debug C# macros. I'm not sure why. The best thing about Qt is that it is open source. If you need to, you can fix it. I don't have direct experience with PyQt but it has been around for quite a while. .Net is .Net and as usual with Microsoft, a moving target. You will sacrifice speed for ease of coding. The IronPython group seems good but I'm not sure if Microsoft's commitment is there. Visual Studio support isn't there yet although the plans sound good. After all, MS only really cares if they own everything, which is not the case for Python. What I really expect is MS will create a dynamic version of C#, interpreter and all, and tell all the Python programmers that it is better and supported and well integrated with .Net. They will then through their considerable weight behind crushing Python like they've done to Java. Good luck. It's a big decision.
5
8
0
I'm new in using Python. I would like to develop Windows GUI Application using Python. After some research, I found that I have 2 options:- IronPython + .NET Framework Python + PyQt May I know which one is better for Windows Application development? Which option has more features (e.g. database support, etc)? Other than the .NET support, is there any big difference between IronPython and Python? Which one is a better choice for me? Thank you. Patrick.L
"IronPython + .NET" vs "Python + PyQt". Which one is better for Windows App development?
0.197375
0
0
5,960
2,657,036
2010-04-17T02:52:00.000
3
0
0
0
.net,python,user-interface,ironpython,pyqt
2,658,657
5
false
0
1
PyQt is a great library, but .NET is the best way to go for Windows. That is because you can use any GUI controls that C# would be able to use in Python. Furthermore, in addition to WinForms, IronPython can be used to create WPF applications, which look good. The main difference is the features, and PyQt has more cross-platform features, and .NET definitely has the edge in Windows.
5
8
0
I'm new in using Python. I would like to develop Windows GUI Application using Python. After some research, I found that I have 2 options:- IronPython + .NET Framework Python + PyQt May I know which one is better for Windows Application development? Which option has more features (e.g. database support, etc)? Other than the .NET support, is there any big difference between IronPython and Python? Which one is a better choice for me? Thank you. Patrick.L
"IronPython + .NET" vs "Python + PyQt". Which one is better for Windows App development?
0.119427
0
0
5,960
2,657,036
2010-04-17T02:52:00.000
1
0
0
0
.net,python,user-interface,ironpython,pyqt
2,657,263
5
false
0
1
I haven't used IronPython with .NET, but I have written a lot of PyQt code. From my experience, PyQt is a great library. It is a very well executed bindings to Qt, which is a very well known and widely used library. Since it's standard Python you're writing, you can enjoy all the Python standard library which gives you a ton of capabilities, in addition to several useful Qt modules imported with PyQt. Writing PyQt code is productive, and the GUIs come out pretty and responsive. And you can't ignore the portability benefit: with just the tiniest modifications, if any, you can just run these programs on Linux and they will just work.
5
8
0
I'm new in using Python. I would like to develop Windows GUI Application using Python. After some research, I found that I have 2 options:- IronPython + .NET Framework Python + PyQt May I know which one is better for Windows Application development? Which option has more features (e.g. database support, etc)? Other than the .NET support, is there any big difference between IronPython and Python? Which one is a better choice for me? Thank you. Patrick.L
"IronPython + .NET" vs "Python + PyQt". Which one is better for Windows App development?
0.039979
0
0
5,960
2,657,036
2010-04-17T02:52:00.000
3
0
0
0
.net,python,user-interface,ironpython,pyqt
2,657,059
5
false
0
1
First, there are lots more than 2 options (python has more GUI libraries than you can shake a stick at), but let's go on your premise for a minute. "Better" being subjective begs the question: "what do you want to learn?" If the goal is Windows GUI Applications development, than I'd go with .Net. .Net is well respected, there is lots of work for .Net programmers, and it's windows centric nature (yeah I know there's Mono but still) means you aren't trying to think about details of three+ sets of user expectations. If the goal is to learn widely used Python libraries and techniques, I'd go with PyQt (and recently did). It's cross-platform, well respected, and has a large community. But you lose the chance to learn the .Net platform as part of this project. I don't think you can loose either way if your goal is to learn. If your goal is to get something done, think about the long-term plans for the project and where its going over the long run. Do you want something that's well integrated into the Windows user-interface, and uses standard widgets? Do you want something that can easily be adapted to other platforms in the future?
5
8
0
I'm new in using Python. I would like to develop Windows GUI Application using Python. After some research, I found that I have 2 options:- IronPython + .NET Framework Python + PyQt May I know which one is better for Windows Application development? Which option has more features (e.g. database support, etc)? Other than the .NET support, is there any big difference between IronPython and Python? Which one is a better choice for me? Thank you. Patrick.L
"IronPython + .NET" vs "Python + PyQt". Which one is better for Windows App development?
0.119427
0
0
5,960
2,657,627
2010-04-17T07:26:00.000
1
0
1
0
python,magic-methods
5,201,056
7
false
0
0
While the reason is mostly historic, there are some peculiarities in Python's len that make the use of a function instead of a method appropriate. Some operations in Python are implemented as methods, for example list.index and dict.append, while others are implemented as callables and magic methods, for example str and iter and reversed. The two groups differ enough so the different approach is justified: They are common. str, int and friends are types. It makes more sense to call the constructor. The implementation differs from the function call. For example, iter might call __getitem__ if __iter__ isn't available, and supports additional arguments that don't fit in a method call. For the same reason it.next() has been changed to next(it) in recent versions of Python - it makes more sense. Some of these are close relatives of operators. There's syntax for calling __iter__ and __next__ - it's called the for loop. For consistency, a function is better. And it makes it better for certain optimisations. Some of the functions are simply way too similar to the rest in some way - repr acts like str does. Having str(x) versus x.repr() would be confusing. Some of them rarely use the actual implementation method, for example isinstance. Some of them are actual operators, getattr(x, 'a') is another way of doing x.a and getattr shares many of the aforementioned qualities. I personally call the first group method-like and the second group operator-like. It's not a very good distinction, but I hope it helps somehow. Having said this, len doesn't exactly fit in the second group. It's more close to the operations in the first one, with the only difference that it's way more common than almost any of them. But the only thing that it does is calling __len__, and it's very close to L.index. However, there are some differences. For example, __len__ might be called for the implementation of other features, such as bool, if the method was called len you might break bool(x) with custom len method that does completely different thing. In short, you have a set of very common features that classes might implement that might be accessed through an operator, through a special function (that usually does more than the implementation, as an operator would), during object construction, and all of them share some common traits. All the rest is a method. And len is somewhat of an exception to that rule.
3
105
0
I've been playing around with Python recently, and one thing I'm finding a bit odd is the extensive use of 'magic methods', e.g. to make its length available, an object implements a method, def __len__(self), and then it is called when you write len(obj). I was just wondering why objects don't simply define a len(self) method and have it called directly as a member of the object, e.g. obj.len()? I'm sure there must be good reasons for Python doing it the way it does, but as a newbie I haven't worked out what they are yet.
Why does Python use 'magic methods'?
0.028564
0
0
30,752
2,657,627
2010-04-17T07:26:00.000
4
0
1
0
python,magic-methods
2,657,834
7
false
0
0
They are not really "magic names". It's just the interface an object has to implement to provide a given service. In this sense, they are not more magic than any predefined interface definition you have to reimplement.
3
105
0
I've been playing around with Python recently, and one thing I'm finding a bit odd is the extensive use of 'magic methods', e.g. to make its length available, an object implements a method, def __len__(self), and then it is called when you write len(obj). I was just wondering why objects don't simply define a len(self) method and have it called directly as a member of the object, e.g. obj.len()? I'm sure there must be good reasons for Python doing it the way it does, but as a newbie I haven't worked out what they are yet.
Why does Python use 'magic methods'?
0.113791
0
0
30,752
2,657,627
2010-04-17T07:26:00.000
21
0
1
0
python,magic-methods
2,657,649
7
false
0
0
From the Zen of Python: In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. This is one of the reasons - with custom methods, developers would be free to choose a different method name, like getLength(), length(), getlength() or whatsoever. Python enforces strict naming so that the common function len() can be used. All operations that are common for many types of objects are put into magic methods, like __nonzero__, __len__ or __repr__. They are mostly optional, though. Operator overloading is also done with magic methods (e.g. __le__), so it makes sense to use them for other common operations, too.
3
105
0
I've been playing around with Python recently, and one thing I'm finding a bit odd is the extensive use of 'magic methods', e.g. to make its length available, an object implements a method, def __len__(self), and then it is called when you write len(obj). I was just wondering why objects don't simply define a len(self) method and have it called directly as a member of the object, e.g. obj.len()? I'm sure there must be good reasons for Python doing it the way it does, but as a newbie I haven't worked out what they are yet.
Why does Python use 'magic methods'?
1
0
0
30,752
2,658,026
2010-04-17T10:22:00.000
0
1
1
0
python,unit-testing,datetime,testing,time
2,658,048
6
false
0
0
there might be few ways of doing this, like creating the orders (with the current timestamp) and then changing that value in the DB directly by some external process (assuming data is in the DB). I'll suggest something else. Have you though about running your application in a virtual machine, setting the time to say Feb, creating orders, and then just changing the VMs time? This approach is the closest as you can get to the real-life situation.
1
24
0
When I write with business logic, my code often depends on the current time. For example the algorithm which looks at each unfinished order and checks if an invoice should be sent (which depends on the no of days since the job was ended). In these cases creating an invoice is not triggered by an explicit user action but by a background job. Now this creates a problem for me when it comes to testing: I can test invoice creation itself easily However it is hard to create an order in a test and check that the background job identifies the correct orders at the correct time. So far I found two solutions: In the test setup, calculate the job dates relative to the current date. Downside: The code becomes quite complicated as there are no explicit dates written anymore. Sometimes the business logic is pretty complex for edge cases so it becomes hard to debug due to all these relative dates. I have my own date/time accessor functions which I use throughout my code. In the test I just set a current date and all modules get this date. So I can simulate an order creation in February and check that the invoice is created in April easily. Downside: 3rd party modules do not use this mechanism so it's really hard to integrate+test these. The second approach was way more successful to me after all. Therefore I'm looking for a way to set the time Python's datetime+time modules return. Setting the date is usually enough, I don't need to set the current hour or second (even though this would be nice). Is there such a utility? Is there an (internal) Python API that I can use?
How to change the date/time in Python for all modules?
0
0
0
12,107
2,658,779
2010-04-17T14:58:00.000
0
0
1
0
python,pythonpath,pyscripter
13,216,653
4
false
0
1
I just copied python26.dll from my python folder to pyscripter folder and it worked well... dont know it that is a good way to do it...
3
5
0
I installed PyScript to try it out but it just wont start. It only gives me the error: "Error126: Could not open Dll "python26.dll" followed by: "Python could not be properly initialized. We must quit." I think this may have something to do with the PYTHONPATH but since I'm a newbie and dont know what it is or exactly what to put in the PYTHONPATH, after some googling, I ask here. Also, when I tried to install wxPython it was impossible becouse the PYTHONPATH could not be found.(Just a side note)
How do I make PyScripter work? Says it cant find python26.dll
0
0
0
22,256
2,658,779
2010-04-17T14:58:00.000
0
0
1
0
python,pythonpath,pyscripter
23,843,782
4
false
0
1
I finally got it working by (a) not changing the directory it gets installed in to something else...just left it in c:/programfiles/pyscripter ...and (B) going into the pyscripter folder and in the lib folder extracting the rpyc folder so that there is another rpyc folder inside the lib folder that isnt compressed! hope that helps
3
5
0
I installed PyScript to try it out but it just wont start. It only gives me the error: "Error126: Could not open Dll "python26.dll" followed by: "Python could not be properly initialized. We must quit." I think this may have something to do with the PYTHONPATH but since I'm a newbie and dont know what it is or exactly what to put in the PYTHONPATH, after some googling, I ask here. Also, when I tried to install wxPython it was impossible becouse the PYTHONPATH could not be found.(Just a side note)
How do I make PyScripter work? Says it cant find python26.dll
0
0
0
22,256
2,658,779
2010-04-17T14:58:00.000
0
0
1
0
python,pythonpath,pyscripter
2,658,872
4
false
0
1
Install python. should solve all your problems..
3
5
0
I installed PyScript to try it out but it just wont start. It only gives me the error: "Error126: Could not open Dll "python26.dll" followed by: "Python could not be properly initialized. We must quit." I think this may have something to do with the PYTHONPATH but since I'm a newbie and dont know what it is or exactly what to put in the PYTHONPATH, after some googling, I ask here. Also, when I tried to install wxPython it was impossible becouse the PYTHONPATH could not be found.(Just a side note)
How do I make PyScripter work? Says it cant find python26.dll
0
0
0
22,256
2,660,291
2010-04-17T22:24:00.000
1
0
0
1
python,scripting,drag-and-drop,arguments
2,660,314
3
false
0
0
This really is independent of python. It depends entirely on which file browser you're using and how it supports drag and drop.
2
4
0
I am writing a simple Python script with no GUI. I want to be able to drag and drop multiple files onto my python script and have access to their absolute paths inside of the script. How do I do this in Mac, Linux, and windows? For times sake, just Mac will be fine for now. I've googled this question and only found one related one but it was too confusing. I am currently running Mac OS X Snow Leopard. Any help is much appreciated. Thanks!
In python, how do I drag and drop 1 or more files onto my script as arguments with absolute path? (for windows, linux, and mac)
0.066568
0
0
3,985
2,660,291
2010-04-17T22:24:00.000
1
0
0
1
python,scripting,drag-and-drop,arguments
2,660,293
3
false
0
0
Usually when you drag a file onto a script/executable, the OS passes the path to that file as a command-line argument. Check sys.argv
2
4
0
I am writing a simple Python script with no GUI. I want to be able to drag and drop multiple files onto my python script and have access to their absolute paths inside of the script. How do I do this in Mac, Linux, and windows? For times sake, just Mac will be fine for now. I've googled this question and only found one related one but it was too confusing. I am currently running Mac OS X Snow Leopard. Any help is much appreciated. Thanks!
In python, how do I drag and drop 1 or more files onto my script as arguments with absolute path? (for windows, linux, and mac)
0.066568
0
0
3,985
2,660,316
2010-04-17T22:31:00.000
1
0
0
1
javascript,python,google-app-engine,comet
2,660,540
3
false
1
0
The App Engine roadmap has Comet support, otherwise you will have some difficulty achieving this.
1
3
0
I'm creating a web application on Google AppEngine where I want the user to be notified a quickly as possible after certain events occour. The problem is similar to say a chat server in that I need something happening on one connection (someone is writing a message in a chat room) to propagate to a number of other connections (other people in that chat room gets the message). To get speedy updates from the server to the client I'm planning on using long polling with XmlHttpRequest, hoping that AppEngine won't interfere other than possibly restriing the timeout. The real problem however is efficient notification between connections on AppEngine. Is there any support for this type of cross connection notification on AppEngine that does not involve busy-waiting? The only tools I can think of to do this at all is either using the data storage (slow) or memcache (unreliable), and none of them would let me avoid busy-waiting. Note: I know about XMPP support on AppEngine. It's related, but I want a browser based solution, sending messages to the users by XMPP is not an option.
How can I implement "real time" messaging on Google AppEngine?
0.066568
0
0
554
2,661,069
2010-04-18T03:56:00.000
1
0
1
0
python-3.x
8,859,319
3
false
0
0
Pexpect has not been ported to python3, and apparently the author has no plans on doing so. I tried converting it with the python 2to3 program, but could not get it to work.
2
2
0
i have installed pexpect with the following command "python setup.py install" but when i try to run a program it says "AttributeError: 'module' object has no attribute 'spawn'". how to settle the matter?
pexpect install problem
0.066568
0
0
1,337
2,661,069
2010-04-18T03:56:00.000
2
0
1
0
python-3.x
4,926,558
3
false
0
0
It looks like pexpect wasn't ported yet to python 3 (quite a late answer, but still usable for people googling here)
2
2
0
i have installed pexpect with the following command "python setup.py install" but when i try to run a program it says "AttributeError: 'module' object has no attribute 'spawn'". how to settle the matter?
pexpect install problem
0.132549
0
0
1,337
2,661,778
2010-04-18T09:39:00.000
2
0
0
0
python,tags,machine-learning,nlp,nltk
2,661,789
5
false
0
0
A very simple solution to the problem would be: count the occurences of each word in the text consider the most frequent terms as the key phrases have a black-list of 'stop words' to remove common words like the, and, it, is etc I'm sure there are cleverer, stats based solutions though. If you need a solution to use in a larger project rather than for interests sake, Yahoo BOSS has a key term extraction method.
1
50
1
I am curious if there is an algorithm/method exists to generate keywords/tags from a given text, by using some weight calculations, occurrence ratio or other tools. Additionally, I will be grateful if you point any Python based solution / library for this. Thanks
tag generation from a text content
0.07983
0
0
28,812
2,662,595
2010-04-18T14:46:00.000
1
0
1
0
python,html,screen-scraping,hyperlink
2,663,277
1
true
0
0
Ways out. Parallelise Profile your code to see where the bottleneck is. The result are often surprising. Use a single regexp (concatenate using |) rather than multiple ones.
1
2
0
I have around 5 GB of html data which I want to process to find links to a set of websites and perform some additional filtering. Right now I use simple regexp for each site and iterate over them, searching for matches. In my case links can be outside of "a" tags and be not well formed in many ways(like "\n" in the middle of link) so I try to grab as much "links" as I can and check them later in other scripts(so no BeatifulSoup\lxml\etc). The problem is that my script is pretty slow, so I am thinking about any ways to speed it up. I am writing a set of test to check different approaches, but hope to get some advices :) Right now I am thinking about getting all links without filtering first(maybe using C module or standalone app, which doesn't use regexp but simple search to get start and end of every link) and then using regexp to match ones I need.
Extract anything that looks like links from large amount of data in python
1.2
0
1
156
2,662,852
2010-04-18T15:57:00.000
0
0
0
1
python,command-line,time
5,870,949
2
false
0
0
You can use the timeit module to time code snippets (say, a function that launches external commands using subprocess module as described in the answer above) and save the data to a csv file. You can do statistics on the csv data using a stats module or externally using Excel/ LogParser/ R etc. Another approach is to use the hotshot profiler that does the profiling and also returns stats that you can either print using print_stats() method or save to a file by iterating over.
1
1
0
I want to run the 'time' unix command from a Python script, to time the execution of a non Python app. I would use the os.system method. Is there any way to save the output of this in Python? My goal is to run the app several times, save their execution times and then do some statistics on them. Thank You
Python run command line (time)
0
0
0
1,310