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
1,524,713
2009-10-06T10:15:00.000
0
0
0
0
python,django
1,524,724
4
false
1
0
You could make a Date object in javascript. Check the current time and depending on the time, you set the img src to whatever image you want for that time of day :) or hide the image through myimg.style.visibility = "hidden" if you dont want to display an image at that moment.
2
1
0
I'm supposed to display images at certain times of the day on the webpage, Please can anyone tell me how to go about it
How do I display images at different times on webpage
0
0
1
328
1,524,713
2009-10-06T10:15:00.000
0
0
0
0
python,django
1,524,812
4
false
1
0
If you need to change the image before a page refresh, you could use jquery ajax call to get the correct image. jquery has some interval functionality which would allow this.
2
1
0
I'm supposed to display images at certain times of the day on the webpage, Please can anyone tell me how to go about it
How do I display images at different times on webpage
0
0
1
328
1,527,230
2009-10-06T18:21:00.000
0
0
0
0
python,rss,python-3.x,feed
1,568,128
4
false
0
0
Start porting feedparser to Python 3.1.
1
8
0
Anyone know of a good feed parser for python 3.1? I was using feedparser for 2.5 but it doesn't seem to be ported to 3.1 yet, and it's apparently more complicated than just running 2to3.py on it. Any help?
Python 3.1 RSS Parser?
0
0
1
3,122
1,527,395
2009-10-06T18:56:00.000
3
0
1
0
python,properties,instance,setter,instance-variables
1,527,494
4
false
0
0
Simply trusting the user is not necessarily a bad thing; if you are just writing a quick Python program to be used once and thrown away, you might very well just trust that the user not alter the pid field. IMHO the most Pythonic way to enforce the read-only field is to use a property that raises an exception on an attempt to set the field. So, IMHO you have good instincts about this stuff.
1
9
0
I use @property to ensure that changes to an objects instance variables are wrapped by methods where I need to. What about when an instance has an variable that logically should not be changed? Eg, if I'm making a class for a Process, each Process instance should have a PID attribute that will frequently be accessed but should not be changed. What's the most Pythonic way to handle someone attempting to modify that instance variable? Simply trust the user not to try and change something they shouldn't? Use property but raise an exception if the instance variable is changed? Something else?
Constant instance variables?
0.148885
0
0
4,830
1,528,583
2009-10-06T23:10:00.000
11
0
0
0
python,django,voting
1,528,617
4
false
1
0
Whatever you do, make sure that it's submitted by POST and not GET; GET requests should never alter database information.
1
29
0
I am making a small app that lets users vote items either up or down. I'm using Django (and new to it!). I am just wondering, what is the best way to present the upvote link to the user. As a link, button or something else? I have already done something like this in php with a different framework but I'm not sure if I can do it the same way. Should I have a method for up/down vote and then display a link to the user to click. When they click it, it performs the method and refreshes the page?
Django Vote Up/Down method
1
0
0
12,621
1,529,128
2009-10-07T01:59:00.000
0
0
0
0
python,windows,django,authentication,frameworks
1,529,146
2
false
1
0
If the only thing the WIN32 app uses the MS-SQL Server for is Authentication/Authorization then you could write a new Authentication/Authorization provider that uses a set of Web Services (that you would have to create) that expose the Django provider.
1
1
0
I have a web service with Django Framework. My friend's project is a WIN32 program and also a MS-sql server. The Win32 program currently has a login system that talks to a MS-sql for authentication. However, we would like to INTEGRATE this login system as one. Please answer the 2 things: I want scrap the MS-SQL to use only the Django authentication system on the linux server. Can the WIN32 client talk to Django using a Django API (login)? If not, what is the best way of combining the authentication?
Can a WIN32 program authenticate into Django authentication system, using MYSQL?
0
1
0
203
1,529,584
2009-10-07T05:07:00.000
1
0
1
1
python,macos,osx-leopard
1,529,596
3
false
0
0
It probably failed because /var/log has user set to root and group set to wheel. Try running your python code as root and it will probably work.
1
1
0
how can i create new file in /var/log directory using python language in OSX leopard? i tried to do it using os.open function but i get "permission denied" thanks in advance
how to create new file using python
0.066568
0
0
1,509
1,529,896
2009-10-07T06:41:00.000
2
1
0
0
python,ruby,scripting-language
1,529,931
11
false
0
0
Script languages have no differences compared with other languages in the sense that you still have to break your problems into manageable pieces -- that is, functions. So, instead of testing the whole script after finishing the whole script, I prefer to test those small functions before integrating them. TDD always helps.
4
6
0
I am basically from the world of C language programming, now delving into the world of scripting languages like Ruby and Python. I am wondering how to do debugging. At present the steps I follow is, I complete a large script, Comment everything but the portion I want to check Execute the script Though it works, I am not able to debug like how I would do in, say, a VC++ environment or something like that. My question is, is there any better way of debugging? Note: I guess it may be a repeated question, if so, please point me to the answer.
Debugging a scripting language like ruby
0.036348
0
0
1,224
1,529,896
2009-10-07T06:41:00.000
10
1
0
0
python,ruby,scripting-language
1,529,996
11
true
0
0
Your sequence seems entirely backwards to me. Here's how I do it: I write a test for the functionality I want. I start writing the script, executing bits and verifying test results. I review what I'd done to document and publish. Specifically, I execute before I complete. It's way too late by then. There are debuggers, of course, but with good tests and good design, I've almost never needed one.
4
6
0
I am basically from the world of C language programming, now delving into the world of scripting languages like Ruby and Python. I am wondering how to do debugging. At present the steps I follow is, I complete a large script, Comment everything but the portion I want to check Execute the script Though it works, I am not able to debug like how I would do in, say, a VC++ environment or something like that. My question is, is there any better way of debugging? Note: I guess it may be a repeated question, if so, please point me to the answer.
Debugging a scripting language like ruby
1.2
0
0
1,224
1,529,896
2009-10-07T06:41:00.000
0
1
0
0
python,ruby,scripting-language
1,531,112
11
false
0
0
The debugging method you described is perfect for a static language like C++, but given that the language is so different, the coding methods are similarly different. One of the big very important things in a dynamic language such as Python or Ruby is the interactive toplevel (what you get by typing, say python on the command line). This means that running a part of your program is very easy. Even if you've written a large program before testing (which is a bad idea), it is hopefully separated into many functions. So, open up your interactive toplevel, do an import thing (for whatever thing happens to be) and then you can easily start testing your functions one by one, just calling them on the toplevel. Of course, for a more mature project, you probably want to write out an actual test suite, and most languages have a method to do that (in Python, this is doctest and nose, don't know about other languages). At first, though, when you're writing something not particularly formal, just remember a few simple rules of debugging dynamic languages: Start small. Don't write large programs and test them. Test each function as you write it, at least cursorily. Use the toplevel. Running small pieces of code in a language like Python is extremely lightweight: fire up the toplevel and run it. Compare with writing a complete program and the compile-running it in, say, C++. Use that fact that you can quickly change the correctness of any function. Debuggers are handy. But often, so are print statements. If you're only running a single function, debugging with print statements isn't that inconvenient, and also frees you from dragging along an IDE.
4
6
0
I am basically from the world of C language programming, now delving into the world of scripting languages like Ruby and Python. I am wondering how to do debugging. At present the steps I follow is, I complete a large script, Comment everything but the portion I want to check Execute the script Though it works, I am not able to debug like how I would do in, say, a VC++ environment or something like that. My question is, is there any better way of debugging? Note: I guess it may be a repeated question, if so, please point me to the answer.
Debugging a scripting language like ruby
0
0
0
1,224
1,529,896
2009-10-07T06:41:00.000
2
1
0
0
python,ruby,scripting-language
1,530,723
11
false
0
0
My question is, is there any better way of debugging?" Yes. Your approach, "1. I complete a large script, 2. Comment everything but the portion I want to check, 3. Execute the script" is not really the best way to write any software in any language (sorry, but that's the truth.) Do not write a large anything. Ever. Do this. Decompose your problem into classes of objects. For each class, write the class by 2a. Outline the class, focus on the external interface, not the implementation details. 2b. Write tests to prove that interface works. 2c. Run the tests. They'll fail, since you only outlined the class. 2d. Fix the class until it passes the test. 2e. At some points, you'll realize your class designs aren't optimal. Refactor your design, assuring your tests still pass. Now, write your final script. It should be short. All the classes have already been tested. 3a. Outline the script. Indeed, you can usually write the script. 3b. Write some test cases that prove the script works. 3c. Runt the tests. They may pass. You're done. 3d. If the tests don't pass, fix things until they do. Write many small things. It works out much better in the long run that writing a large thing and commenting parts of it out.
4
6
0
I am basically from the world of C language programming, now delving into the world of scripting languages like Ruby and Python. I am wondering how to do debugging. At present the steps I follow is, I complete a large script, Comment everything but the portion I want to check Execute the script Though it works, I am not able to debug like how I would do in, say, a VC++ environment or something like that. My question is, is there any better way of debugging? Note: I guess it may be a repeated question, if so, please point me to the answer.
Debugging a scripting language like ruby
0.036348
0
0
1,224
1,530,245
2009-10-07T08:21:00.000
0
1
1
0
c++,python,garbage-collection
1,532,646
6
false
0
0
As you have got your answer, now it's better to know the cons of automated garbage collection: it requires large amounts of extra memory and not suitable for hard real-time deadline applications.
2
3
0
I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?
I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?
0
0
0
1,606
1,530,245
2009-10-07T08:21:00.000
2
1
1
0
c++,python,garbage-collection
1,530,267
6
false
0
0
It basically means the way they handle memory resources. When you need memory you usually ask for it to the OS and then return it back. With python you don't need to worry about returning it, with C++ you need to track what you asked and return it back, one is easier, the other performant, you choose your tool.
2
3
0
I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?
I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?
0.066568
0
0
1,606
1,530,960
2009-10-07T11:08:00.000
1
0
0
0
python,numpy,memory-management
1,534,340
4
false
0
0
On possible option is to do a single pass through the file first to count the number of rows, without loading them. The other option is to double your table size each time, which has two benefits: You will only re-alloc memory log(n) times where n is the number of rows. You only need 50% more ram than your largest table size If you take the dynamic route, you could measure the length of the first row in bytes, then guess the number of rows by calculating (num bytes in file / num bytes in first row). Start with a table of this size.
1
11
1
I have a series of large text files (up to 1 gig) that are output from an experiment that need to be analysed in Python. They would be best loaded into a 2D numpy array, which presents the first question: As the number of rows is unknown at the beginning of the loading, how can a very large numpy array be most efficiently built, row by row? Simply adding the row to the array would be inefficient in memory terms, as two large arrays would momentarily co-exist. The same problem would seem to be occur if you use numpy.append. The stack functions are promising, but ideally I would want to grow the array in place. This leads to the second question: What is the best way to observe the memory usage of a Python program that heavily uses numpy arrays? To study the above problem, I've used the usual memory profiling tools - heapy and pympler - but am only getting the size of the outer array objects (80 bytes) and not the data they are containing. Asides from a crude measuring of how much memory the Python process is using, how can I get at the "full" size of the arrays as they grow? Local details: OSX 10.6, Python 2.6, but general solutions are welcome.
Incrementally building a numpy array and measuring memory usage
0.049958
0
0
6,464
1,531,551
2009-10-07T13:10:00.000
12
0
1
0
python,vim
4,533,586
11
false
0
0
If you want to yank everything except the { use yi{ (or yi}). If you to include the curly braces use ya{ (or ya}). The i and a modifiers mean in and all. To yank a word no matter where in the word you are: yiw To yank the contents of parentheses: yi); if you want to include them, use ya( You can do the same for " or ' with yi", ya" or yi' and ya'. Of course, you're not limited to yanking. You can delete a word with diw or change it with ciw, etc... etc...
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
1
0
0
17,152
1,531,551
2009-10-07T13:10:00.000
31
0
1
0
python,vim
1,531,576
11
true
0
0
You can yank a paragraph with y}. This will not yank all the methods if you have a blank line though.
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
1.2
0
0
17,152
1,531,551
2009-10-07T13:10:00.000
0
0
1
0
python,vim
46,510,217
11
false
0
0
Just fold the class using za and then use visual mode ( V ) to select the collapsed class. This way you don't have to scroll too much. Then just yank with y. When you are done yanking unfold the class with za again.
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
0
0
0
17,152
1,531,551
2009-10-07T13:10:00.000
4
0
1
0
python,vim
1,534,987
11
false
0
0
You can combine a search with yank, so if your function ends with return retval you can type y/return retval
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
0.072599
0
0
17,152
1,531,551
2009-10-07T13:10:00.000
2
0
1
0
python,vim
1,534,960
11
false
0
0
Enter visual line selection by pressing 'V' When finished selecting the block pres 'y' Paste it somewhere with 'p' or 'P'
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
0.036348
0
0
17,152
1,531,551
2009-10-07T13:10:00.000
4
0
1
0
python,vim
1,531,977
11
false
0
0
I usually just use visual block mode. Shift-V, move, and 'y'ank the highlighted block. There's only so many shortcuts I can keep in memory at once :)
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
0.072599
0
0
17,152
1,531,551
2009-10-07T13:10:00.000
0
0
1
0
python,vim
46,537,673
11
false
0
0
In .py file, press Esc Press shift V to enter visual line mode Highlight with up and down arrow keys Press d to delete the selected rows Go to the row you would like to place the lines and press p to paste lines after a row or press shift P to paste before a row Hope that helps.
7
26
0
Is it possible to yank an entire block of Python code in Vim? Be it a def, for, if, etc. block...
How to yank an entire block in Vim?
0
0
0
17,152
1,532,306
2009-10-07T15:20:00.000
2
0
1
1
python,windows,registry
1,532,868
3
false
0
0
HKEY_CURRENT_USER maps to a HKEY_USERS\{id} key. Try finding the id by matching the HKEY_USERS{id}\Volatile Environment\USERNAME key to the username of the user (by enumerating/iterating over the {id}s that are present on the system). When you find the match just use HKEY_USERS{id} as if it was HKEY_CURRENT_USER
1
1
0
In my application I run subprocesses under several different user accounts. I need to be able to read some of the information written to the registry by these subprocesses. Each one is writing to HKEY_CURRENT_USER, and I know the user account name that they are running under. In Python, how can I read values from HKEY_CURRENT_USER for a specific user? I assume I need to somehow load the registry values under the user's name, and then read them from there, but how? edit: Just to make sure it's clear, my Python program is running as Administrator, and I have accounts "user1", "user2", and "user3", which each have information in their own HKEY_CURRENT_USER. As Administrator, how do I read user1's HKEY_CURRENT_USER data?
Reading HKEY CURRENT USER from the registry in Python, specifying the user
0.132549
0
0
8,899
1,532,720
2009-10-07T16:28:00.000
5
1
1
0
python,multithreading,md5,crc32,hashlib
1,533,036
6
false
0
0
It's an algorithm selection problem, rather than a library/language selection problem! There appears to be two points to consider primarily: how much would the disk I/O affect the overall performance? what is the expected reliability of the error detection feature? Apparently, the answer to the second question is something like 'some false negative allowed' since the reliability of any 32 bits hash, relative to a 4Gb message, even in a moderately noisy channel, is not going to be virtually absolute. Assuming that I/O can be improved through multithreading, we may choose a hash that doesn't require a sequential scan of the complete message. Instead we can maybe work the file in parallel, hashing individual sections and either combining the hash values or appending them, to form a longer, more reliable error detection device. The next step could be to formalize this handling of files as ordered sections, and to transmit them as such (to be re-glued together at the recipient's end). This approach, along additional information about the way the files are produced (for ex. they may be exclusively modified by append, like log files), may even allow to limit the amount of hash calculation required. The added complexity of this approach needs to weighted against the desire to have zippy fast CRC calculation. Side note: Alder32 is not limited to message sizes below a particular threshold. It may just be a limit of the zlib API. (BTW, the reference I found about zlib.adler32 used a buffer, and well... this approach is to be avoided in the context of our huge messages, in favor of streamed processes: read a little from file, calculate, repeat..)
5
6
0
i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limitation here? using hashlib.md5 i could get a result but the problem is the speed. it takes roughly about 5 minutes to generate an md5 for 4.8GB file. task manager shows that the process is using one core only. my questions are: is there a way to make crc works on large file? i prefer to use crc than md5 if not then is there a way to speed up the md5.hexdigest()/md5.digest? or in this case any hashlib hexdigest/digest? maybe spliting it into multi thread process? how do i do that? PS: i'm working on somethimg similar like an "Asset Management" system, kind of like svn but the asset consist of large compressed image files. the files have tiny bit incremental changes. the hashing/checksum is needed for detecting changes and error detection.
the fastest way to create checksum for large files in python
0.16514
0
0
17,263
1,532,720
2009-10-07T16:28:00.000
1
1
1
0
python,multithreading,md5,crc32,hashlib
1,532,764
6
false
0
0
You cannot possibly use more than one core to calculate MD5 hash of a large file because of the very nature of MD5: it expects a message to be broken up in chunks and fed into hashing function in strict sequence. However, you can use one thread to read a file into internal queue, and then calculate hash in a separate thread so that. I do not think though that this will give you any significant performance boost. The fact that it takes so long to process a big file might be due to "unbuffered" reads. Try reading, say, 16 Kb at a time and then feed the content in chunks to hashing function.
5
6
0
i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limitation here? using hashlib.md5 i could get a result but the problem is the speed. it takes roughly about 5 minutes to generate an md5 for 4.8GB file. task manager shows that the process is using one core only. my questions are: is there a way to make crc works on large file? i prefer to use crc than md5 if not then is there a way to speed up the md5.hexdigest()/md5.digest? or in this case any hashlib hexdigest/digest? maybe spliting it into multi thread process? how do i do that? PS: i'm working on somethimg similar like an "Asset Management" system, kind of like svn but the asset consist of large compressed image files. the files have tiny bit incremental changes. the hashing/checksum is needed for detecting changes and error detection.
the fastest way to create checksum for large files in python
0.033321
0
0
17,263
1,532,720
2009-10-07T16:28:00.000
3
1
1
0
python,multithreading,md5,crc32,hashlib
1,533,255
6
false
0
0
First, there is nothing inherent in any of the CRC algorithms that would prevent them working on an arbitrary length of data (however, a particular implementation might well impose a limit). However, in a file syncing application, that probably doesn't matter, as you may not want to hash the entire file when it gets large, just chunks anyway. If you hash the entire file, and the hashes at each end differ, you have to copy the entire file. If you hash fixed sized chunks, then you only have to copy the chunks whose hash has changed. If most of the changes to the files are localized (e.g. database) then this will likely require much less copying (and it' easier to spread per chunk calculations across multiple cores). As for the hash algorithm itself, the basic tradeoff is speed vs. lack of collisions (two different data chunks yielding the same hash). CRC-32 is fast, but with only 2^32 unique values, collisions may be seen. MD5 is much slower, but has 2^128 unique values, so collisions will almost never be seen (but are still theoretically possible). The larger hashes (SHA1, SHA256, ...) have even more unique values, but are slower still: I doubt you need them: you're worried about accidental collisions, unlike digital signature applications, where you're worried about deliberately (malicously) engineered collisions. It sounds like you're trying to do something very similar to what the rsync utility does. Can you just use rsync?
5
6
0
i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limitation here? using hashlib.md5 i could get a result but the problem is the speed. it takes roughly about 5 minutes to generate an md5 for 4.8GB file. task manager shows that the process is using one core only. my questions are: is there a way to make crc works on large file? i prefer to use crc than md5 if not then is there a way to speed up the md5.hexdigest()/md5.digest? or in this case any hashlib hexdigest/digest? maybe spliting it into multi thread process? how do i do that? PS: i'm working on somethimg similar like an "Asset Management" system, kind of like svn but the asset consist of large compressed image files. the files have tiny bit incremental changes. the hashing/checksum is needed for detecting changes and error detection.
the fastest way to create checksum for large files in python
0.099668
0
0
17,263
1,532,720
2009-10-07T16:28:00.000
2
1
1
0
python,multithreading,md5,crc32,hashlib
1,540,992
6
false
0
0
You might be hitting a size limit for files in XP. The 64-bit gives you more addressing space (removing the 2GB (or so) addressing space per application), but probably does nothing for the file size problem.
5
6
0
i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limitation here? using hashlib.md5 i could get a result but the problem is the speed. it takes roughly about 5 minutes to generate an md5 for 4.8GB file. task manager shows that the process is using one core only. my questions are: is there a way to make crc works on large file? i prefer to use crc than md5 if not then is there a way to speed up the md5.hexdigest()/md5.digest? or in this case any hashlib hexdigest/digest? maybe spliting it into multi thread process? how do i do that? PS: i'm working on somethimg similar like an "Asset Management" system, kind of like svn but the asset consist of large compressed image files. the files have tiny bit incremental changes. the hashing/checksum is needed for detecting changes and error detection.
the fastest way to create checksum for large files in python
0.066568
0
0
17,263
1,532,720
2009-10-07T16:28:00.000
1
1
1
0
python,multithreading,md5,crc32,hashlib
1,532,779
6
false
0
0
md5 itself can't be run in parallel. However you can md5 the file in sections (in parallel) and the take an md5 of the list of hashes. However that assumes that the hashing is not IO-limited, which I would suspect it is. As Anton Gogolev suggests - make sure that you're reading the file efficiently (in large power-of-2 chunks). Once you've done that, make sure the file isn't fragmented. Also a hash such as sha256 should be selected rather than md5 for new projects. Are the zlib checksums much faster than md5 for 4Gb files?
5
6
0
i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limitation here? using hashlib.md5 i could get a result but the problem is the speed. it takes roughly about 5 minutes to generate an md5 for 4.8GB file. task manager shows that the process is using one core only. my questions are: is there a way to make crc works on large file? i prefer to use crc than md5 if not then is there a way to speed up the md5.hexdigest()/md5.digest? or in this case any hashlib hexdigest/digest? maybe spliting it into multi thread process? how do i do that? PS: i'm working on somethimg similar like an "Asset Management" system, kind of like svn but the asset consist of large compressed image files. the files have tiny bit incremental changes. the hashing/checksum is needed for detecting changes and error detection.
the fastest way to create checksum for large files in python
0.033321
0
0
17,263
1,533,259
2009-10-07T02:00:00.000
1
0
0
0
python,mysql,windows,django
1,581,622
1
true
1
0
The Win32 client can act like a web client to pass the user's credentials to the server. You will want to store the session cookie you get once you are authenticated and use that cookie in all following requests
1
0
0
I have a web service with Django Framework. My friend's project is a WIN32 program and also a MS-sql server. The Win32 program currently has a login system that talks to a MS-sql for authentication. However, we would like to INTEGRATE this login system as one. Please answer the 2 things: I want scrap the MS-SQL to use only the Django authentication system on the linux server. Can the WIN32 client talk to Django using a Django API (login)? If not, what is the best way of combining the authentication?
Can a WIN32 program authenticate into Django authentication system, using MYSQL?
1.2
1
0
103
1,534,070
2009-10-07T20:40:00.000
2
0
0
0
python
1,537,103
8
false
1
0
Whose web server? If it is a web server provided by a web hosting company or someone else and you don't have control over it, you need to ascertain in what way they support the use of Python for writing web applications. It isn't enough to know just that they have Python available. As pointed out by others, is likely that at least CGI scripts which use Python will be supported. CGI however is not really practical for running large Python web frameworks such as Django. It is possible though that the web server might also support FASTCGI. If that is the case it becomes possible to use such larger Python web frameworks as FASTCGI uses persistent processes where as CGI creates a process for each request, where the overhead of large Python web frameworks generally makes the use of CGI impractical as a result. If the Apache server is controlled by others using a standalone Python web server such as wsgiref and proxying to it from Apache isn't going to be doable either as you can't setup Apache to do it. So, find out how use of Python for web applications is supported and work out whether you are just a user of the Apache instance, or whether you have some measure of control of changing its global configuration files and restarting it. This will dictate what you can do and use.
1
11
0
Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes: I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code. I never done any Python programming for web, and couldn't figure it out... I need to have a page (OK, I know how to upload files to a server, Apache is running, Python is installed on the server...) with an edit field, which will accept that parameter, and Submit button, and I need it to "print" the results on a web page after the user submitted a proper parameter, or show any output that in a command-line situation are printed. I've read Dive Into Python's chapters about "HTML Processing" and "HTTP Web Services", but they do not describe what I'm looking for. If the answer isn't short, I would very much appreciate links to the more relevant stuff to read or maybe the key words to google for it.
Python: how to show results on a web page?
0.049958
0
0
29,818
1,534,210
2009-10-07T21:11:00.000
1
0
1
1
python,virtualenv,virtualenvwrapper
65,076,532
36
false
0
0
Surprised that no one has mentioned conda so far. I have found this is a lot more straightforward than the other methods mentioned here. Let's say I have python 3.9 and python 2.7 and a project I am working on was python 3.5.4, I could simply create the isolated virtual env for 3.5.4 with the conda command without downloading anything else. To see a list of available python versions first, use the command conda search "^python$" To create the virtual environment for python version x.y.z, use the command conda create -n yourenvname python=x.y.z Activate venv with conda activate yourenvname Deactivate with conda deactivate To delete the virtual environment when done, use the command conda remove -n yourenvname --all
6
1,453
0
I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python? I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?
Use different Python version with virtualenv
0.005555
0
0
1,338,259
1,534,210
2009-10-07T21:11:00.000
1
0
1
1
python,virtualenv,virtualenvwrapper
57,087,622
36
false
0
0
Yes you just need to install the other version of python, and define the location of your other version of python in your command like : virtualenv /home/payroll/Documents/env -p /usr/bin/python3
6
1,453
0
I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python? I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?
Use different Python version with virtualenv
0.005555
0
0
1,338,259
1,534,210
2009-10-07T21:11:00.000
2
0
1
1
python,virtualenv,virtualenvwrapper
55,512,212
36
false
0
0
This was a bug with virtualenv. Just upgrading your pip should be the fix. pip install --upgrade virtualenv
6
1,453
0
I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python? I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?
Use different Python version with virtualenv
0.011111
0
0
1,338,259
1,534,210
2009-10-07T21:11:00.000
1
0
1
1
python,virtualenv,virtualenvwrapper
56,665,285
36
false
0
0
It worked for me on windows with python 2 installation : Step 1: Install python 3 version . Step 2: create a env folder for the virtual environment. Step 3 : c:\Python37\python -m venv c:\path\to\env. This is how i created Python 3 virtual environment on my existing python 2 installation.
6
1,453
0
I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python? I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?
Use different Python version with virtualenv
0.005555
0
0
1,338,259
1,534,210
2009-10-07T21:11:00.000
23
0
1
1
python,virtualenv,virtualenvwrapper
51,188,487
36
false
0
0
These two commands should work fine. virtualenv -p python2 myenv (For python2) virtualenv -p python3 myenv (For python3)
6
1,453
0
I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python? I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?
Use different Python version with virtualenv
1
0
0
1,338,259
1,534,210
2009-10-07T21:11:00.000
8
0
1
1
python,virtualenv,virtualenvwrapper
39,574,443
36
false
0
0
Even easier, by using command substitution to find python2 for you: virtualenv -p $(which python2) <path/to/new/virtualenv/> Or when using virtualenvwrapper : mkvirtualenv -p $(which python2) <env_name>
6
1,453
0
I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python? I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?
Use different Python version with virtualenv
1
0
0
1,338,259
1,534,450
2009-10-07T21:52:00.000
0
1
1
0
c#,c++,python
1,534,470
10
false
0
1
As someone familiar with C# and .NET you should consider IronPython. Python for .NET. This would be a good way to leverage what you know and learn a new dynamic language at the same time.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
7
1
1
0
c#,c++,python
1,534,460
10
false
0
1
I Am a little scared of C++ because developing anything in it takes ages. I'm not sure how you can say that when you say yourself that you have no experience in the language. C++ is a good tool for some things, Python is good for other things. What you want to do should be driving this decision, not the technology in and of itself. C# programmer or not, I would assume that you can pick up any language, but a language is just a tool, so your question is difficult to answer.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
1
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
5
1
1
0
c#,c++,python
1,534,467
10
false
0
1
Python may be easier to get started with, but a dynamically typed scripting language is a very different language from C# or C++. You will learn more about programming learning it than you will by hopping to a close cousin of a language you already know. Really, solid familiarity with at least one scripting language (Python, Perl and Ruby are the favorites) should be a requirement for all programmers.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0.099668
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
2
1
1
0
c#,c++,python
1,534,729
10
true
0
1
C# is a little closer to Java and C++ than it is to Python, so learn Python first out of the two. However, my advice would be: Stick with your current language and learn more techniques, such as a wider range of algorithms, functional programming, design by contract, unit testing, OOAD, etc. learn C (focus on figuring out pointers, multi-dimensional arrays, data structures like linked lists, and resource management like memory allocation/deallocation, file handles, etc) learn Assembly (on a modern platform with a flat memory architecture, but doing low-level stuff like talking to hardware or drawing on a canvas) learn Python or Ruby. Chances are, you'll stick with one of these for a while, knowing all of the above, unless some hot new language has come along by then.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
1.2
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
3
1
1
0
c#,c++,python
1,534,483
10
false
0
1
If you want to apply to Google then Python might be the one to go for, surely MS would like the C# already. If nothing else the competition would not be as fierce as there are much more folk out there with multi years of C++ experience. Also Python gives you a broader language skill and would be a good path to more languages and scripting. But as said and will be said again, choose your tool wisely and see whether it's a nail or a screw you're trying to secure.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0.059928
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
0
1
1
0
c#,c++,python
1,534,589
10
false
0
1
You might be interested in looking at Windows Powershell. It's the latest scripting technology from Microsoft, built on .NET, and can be extended via C#. Granted, it's not as portable as C++ or Python, but it would leverage your C#/.NET experience more readily. Otherwise, I would suggest C++ (and possibly C). Microsoft builds a lot more of its products with C/C++ than with Python.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
1
1
1
0
c#,c++,python
1,534,645
10
false
0
1
C++ is usually used when speed, and low-level OS access is involved. It's a good skill to have if you want to expand. Python allows you to do thing quickly, and it's quite easy to learn, and provides more power than you'd expect from a scripting language, and probably one of the fastest ones out there. C++ isn't exactly slow to develop, if you've got an IDE, it's not hard to write per-se, but the syntax is going to get you.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0.019997
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
1
1
1
0
c#,c++,python
1,534,651
10
false
0
1
If you want to apply to Google and/ or Microsoft then I'd say that of the two you need both! Given more choice, probably C++ and one other language - either dynamic, functional, or both (Scala might be a good choice too). It's not necessarily about whether you'd use the languages themselves but more about the different approaches they require and encourage. If you continue to be "scared" by C++ you're probably going to struggle applying as a dev at either of those organisations - unless you are highly specialised elsewhere.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0.019997
0
0
1,673
1,534,450
2009-10-07T21:52:00.000
1
1
1
0
c#,c++,python
1,534,556
10
false
0
1
Why not learn some of each. Studying a language for a week or so won't make you an expert, but it will answer a lot of questions in your head and plant a seed for the future. It's important to not just read through exercises. Find some simple problems that can be programmed in a page or two at most and solve them with each language. That will help you to learn the strengths and weaknesses in the context of the way you think and how you solve problems.
9
2
0
I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# programmer? I am a little scared of C++ because developing anything in it takes ages. Python is easy, but I take it as a child-play language, which still need lots of patching to be some mature development tool/language. Any C# developers having same dilemma?
C++ or Python for C# programmer?
0.019997
0
0
1,673
1,535,261
2009-10-08T02:12:00.000
1
1
0
0
php,python,mysql,tracking
1,535,794
9
false
0
0
If accuracy is important, you can do it slightly slower with MySql... create a HEAP / Memory table to store your counter values. These a in-memory tables that are blazingly fast. You can write the data into a normal table at intervals. Based on the app engine ideas, you could use memcache as a temporary store for your counter. Incrementing a memcache counter is faster than using the MySql heap tables (I think). Once every five or ten seconds, you could read the memcache counter and write that number into your DB.
4
7
0
I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinking of using MySQL to keep track of this, but I'm guessing there's a more efficient way. What are good methods of keeping counters?
How to write an efficient hit counter for websites
0.022219
0
0
6,857
1,535,261
2009-10-08T02:12:00.000
4
1
0
0
php,python,mysql,tracking
1,536,049
9
false
0
0
You could take your webserver's Access log (Apache: access.log) and evaluate it time and again (cronjob) in case you do not need to have the data at hand at the exact moment in time when someone visits your site. Usually, the access.log is generated anyway and contains the requested resource as well as time, date and the user's IP. This way you do not have to route all trafic through a php-script. Lean, mean counting machine.
4
7
0
I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinking of using MySQL to keep track of this, but I'm guessing there's a more efficient way. What are good methods of keeping counters?
How to write an efficient hit counter for websites
0.088656
0
0
6,857
1,535,261
2009-10-08T02:12:00.000
7
1
0
0
php,python,mysql,tracking
1,535,311
9
false
0
0
A fascinating subject. Incrementing a counter, simple as it may be, just has to be a transaction... meaning, it can lock out the whole DB for longer than makes sense!-) It can easily be the bottleneck for the whole system. If you need rigorously exact counts but don't need them to be instantly up-to-date, my favorite approach is to append the countable information to a log (switching logs as often as needed for data freshness purposes). Once a log is closed (with thousands of countable events in it), a script can read it and update all that's needed in a single transaction -- maybe not intuitive, but much faster than thousands of single locks. Then there's extremely-fast counters that are only statistically accurate -- but since you don't say that such imprecision is acceptable, I'm not going to explain them in more depth.
4
7
0
I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinking of using MySQL to keep track of this, but I'm guessing there's a more efficient way. What are good methods of keeping counters?
How to write an efficient hit counter for websites
1
0
0
6,857
1,535,261
2009-10-08T02:12:00.000
0
1
0
0
php,python,mysql,tracking
1,900,337
9
false
0
0
I've done something very similar, on a similar scale (multiple servers, hundreds of domains, several thousand hits per hour) and log file analysis was definitely the way to go. (It also checked hit rates, weighted them by file type, and blacklisted IP addresses at the firewall if they were making too many requests; its intended purpose was to auto-block bad bots, not to just be a counter, but counting was an essential piece of it.) No performance impact on the web server process itself, since it's not doing any additional work there, and you could easily publish periodically-updated hit counts by injecting them into the site's database every minute/5 minutes/100 hits/whatever without having to lock the relevant row/table/database (depending on the locking mechanism in use) on every hit.
4
7
0
I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinking of using MySQL to keep track of this, but I'm guessing there's a more efficient way. What are good methods of keeping counters?
How to write an efficient hit counter for websites
0
0
0
6,857
1,535,702
2009-10-08T04:54:00.000
7
0
1
0
python,standardized
1,537,045
3
false
0
0
There are "standards" and there are "standards". Most folks mostly mean that a standard is passed by a standards-writing organization: ISO, ECMA, EIA, etc. Lawyers call these De Jure Standards. There's the force of law. Further, there are "De Facto Standards". Some folks, also, corrupt the word by adding "Industry Standard", or "vendorname Standard". This is just meaningless marketing noise. A De Facto Standard is something that's standardized in practice (because everyone does it and agrees they're doing it that way) but it is not backed by some standards organization. Python has a De Facto Standard, not a De Jure Standard.
1
20
0
I stumbled upon this 'list of programming' languages and found that popular languages like Python are not standardized? Why is that, and what does 'Standardized' mean anyway?
Python not a standardized language?
1
0
0
4,338
1,537,298
2009-10-08T11:40:00.000
2
1
0
0
python,deployment,virtualenv
1,537,585
3
true
1
0
You already mentioned buildout, and it's all you need. Google for example buildouts for the different parts. Takes a while to set it up the first time, but then you can reuse the setup between different projects too. Let supervisord start everything, not just the python server. Then start supervisord at reboot either fron cron or init.d.
1
2
0
I'm starting a new webapp project in Python to get into the Agile mind-set and I'd like to do things "properly" with regards to deployment. However, I'm finding the whole virtualenv/fabric/zc.buildout/etc stuff a little confusing - I'm used to just FTP'ing PHP files to a server and pointing a webserver at it. After deployment the server set-up would look something like: Nginx --proxy-to--> WSGI Webserver (Spawning) --> WSGI Middleware --> WSGI App (probably MNML or similar) with the python webserver being managed by supervisord. What sort of deployment set-up/packages/apps should I be looking into? And is there a specific directory structure I need to stick to with my app to ease deployment?
What do I need to know/learn for automated python deployment?
1.2
0
0
1,087
1,538,589
2009-10-08T15:36:00.000
0
0
1
0
python
1,538,805
11
false
0
0
What if you break it up into syllables and then use those to construct words to compare to your dictionary. It's still a brute force method, but it would surely speed things up a bit.
3
1
0
I'm wondering how to proceed with this task, take this string for example "thingsandstuff". How could I generate all possible strings out of this string as to look them up individually against an english dictionary? The goal is to find valid english words in a string that does not contain space. Thanks
How to sort all possible words out of a string?
0
0
0
3,534
1,538,589
2009-10-08T15:36:00.000
0
0
1
0
python
1,538,687
11
false
0
0
Well here is my idea Find all possible strings containing 1 character from the original Find all possible strings containing 2 characters from the original ... Same thing up to the length of the original string Then add all up and go match with your dictionary
3
1
0
I'm wondering how to proceed with this task, take this string for example "thingsandstuff". How could I generate all possible strings out of this string as to look them up individually against an english dictionary? The goal is to find valid english words in a string that does not contain space. Thanks
How to sort all possible words out of a string?
0
0
0
3,534
1,538,589
2009-10-08T15:36:00.000
3
0
1
0
python
1,538,637
11
false
0
0
The brute force approach, i.e. checking every substring, is computationally unfeasible even for strings of middling lengths (a string of length N has O(N**2) substrings). Unless there is a pretty tight bound on the length of strings you care about, that doesn't scale well. To make things more feasible, more knowledge is required -- are you interested in overlapping words (eg 'things' and 'sand' in your example) and/or words which would leave unaccounted for characters (eg 'thing' and 'and' in your example, leaving the intermediate 's' stranded), or you do you want a strict partition of the string into juxtaposed (not overlapping) words with no residue? The latter would be the simplest problem, because the degrees of freedom drop sharply -- essentially to trying to determine a sequence of "breaking points", each between two adjacent characters, that would split the string into words. If that's the case, do you need every possible valid split (i.e. do you need both "thing sand" and "things and"), or will any single valid split do, or are there criteria that your split must optimize? If you clarify all of these issues it may be possible to give you more help!
3
1
0
I'm wondering how to proceed with this task, take this string for example "thingsandstuff". How could I generate all possible strings out of this string as to look them up individually against an english dictionary? The goal is to find valid english words in a string that does not contain space. Thanks
How to sort all possible words out of a string?
0.054491
0
0
3,534
1,538,663
2009-10-08T15:48:00.000
9
0
1
0
python,string,immutability,tuples
1,538,689
6
false
0
0
One big advantage of making them immutable is that they can be used as keys in a dictionary. I'm sure the internal data structures used by dictionaries would get quite messed up if the keys were allowed to change.
4
56
0
I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?
Why are python strings and tuples are made immutable?
1
0
0
17,290
1,538,663
2009-10-08T15:48:00.000
3
0
1
0
python,string,immutability,tuples
1,538,686
6
false
0
0
pros: Performance cons: you can't change mutables.
4
56
0
I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?
Why are python strings and tuples are made immutable?
0.099668
0
0
17,290
1,538,663
2009-10-08T15:48:00.000
4
0
1
0
python,string,immutability,tuples
3,165,540
6
false
0
0
Immutable types are conceptually much simpler than mutable ones. For example, you don't have to mess with copy constructors or const-correctness like in C++. The more types are immutable, the easier the language gets. Thus the easiest languages are the pure functional ones without any global state (because lambda calculus is much easier than Turing machines, and equally powerful), although a lot of people don't seem to appreciate this.
4
56
0
I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?
Why are python strings and tuples are made immutable?
0.132549
0
0
17,290
1,538,663
2009-10-08T15:48:00.000
3
0
1
0
python,string,immutability,tuples
10,837,060
6
false
0
0
Perl has mutable strings and seems to function just fine. The above seems like a lot of hand waving and rationalization for an arbitrary design decision. My answer to the question of why Python has immutable strings, because Python creator Guido van Rossum wanted it that way and he now has legions of fans that will defend that arbitrary decision to their dying breath. You could pose a similar question of why Perl doesn't have immutable strings and a whole passel of people would write how awful the very concept of immutable strings are and why it's The Very Bestest Idea Ever (TM) that Perl doesn't have them.
4
56
0
I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?
Why are python strings and tuples are made immutable?
0.099668
0
0
17,290
1,540,011
2009-10-08T19:45:00.000
0
1
0
0
python,http,xml-rpc
1,540,053
3
false
0
0
Is there a reason not to run a real webserver out front with url rewrites to the two ports you are usign now? It's going to make life much easier in the long run
2
0
0
I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port. I think it should be possible to modify the CGIXMLRPCRequestHandler class to also serve custom HTTP requests on some paths, or alternately, to use multiple request handlers based on what path is requested. I'm not really sure what the cleanest way to do this would be, though.
Python HTTP server with XML-RPC
0
0
1
849
1,540,011
2009-10-08T19:45:00.000
0
1
0
0
python,http,xml-rpc
1,543,370
3
true
0
0
Use SimpleXMLRPCDispatcher class directly from your own request handler.
2
0
0
I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port. I think it should be possible to modify the CGIXMLRPCRequestHandler class to also serve custom HTTP requests on some paths, or alternately, to use multiple request handlers based on what path is requested. I'm not really sure what the cleanest way to do this would be, though.
Python HTTP server with XML-RPC
1.2
0
1
849
1,540,214
2009-10-08T20:27:00.000
7
1
0
0
python,client-side
1,540,379
8
false
0
0
Silverlight can run IronPython, so you can make Silverlight applications. Which is client-side.
3
68
0
If yes are there any frameworks/Tutorials/tips/etc recommended? N00b at Python but I have tons of PHP experience and wanted to expand my skill set. I know Python is great at server side execution, just wanted to know about client side as well.
Can Python be used for client side web development?
1
0
1
54,388
1,540,214
2009-10-08T20:27:00.000
-1
1
0
0
python,client-side
1,540,233
8
false
0
0
No. Browsers don't run Python.
3
68
0
If yes are there any frameworks/Tutorials/tips/etc recommended? N00b at Python but I have tons of PHP experience and wanted to expand my skill set. I know Python is great at server side execution, just wanted to know about client side as well.
Can Python be used for client side web development?
-0.024995
0
1
54,388
1,540,214
2009-10-08T20:27:00.000
3
1
0
0
python,client-side
7,437,506
8
false
0
0
On Windows, any language that registers for the Windows Scripting Host can run in IE. At least the ActiveState version of Python could do that; I seem to recall that has been superseded by a more official version these days. But that solution requires the user to install a python interpreter and run some script or .reg file to put the correct "magic" into the registry for the hooks to work.
3
68
0
If yes are there any frameworks/Tutorials/tips/etc recommended? N00b at Python but I have tons of PHP experience and wanted to expand my skill set. I know Python is great at server side execution, just wanted to know about client side as well.
Can Python be used for client side web development?
0.07486
0
1
54,388
1,541,249
2009-10-09T00:21:00.000
48
0
0
0
python,django
1,541,322
1
true
1
0
I don't know if you really need an example, it's quite easy: if you know it's one object that matches your query, use get. It will fail if it's more than one. otherwise use filter, which gives you a list of objects. To be more precise: MyTable.objects.get(id=x).whatever gives you the whatever property of your object. get() raises MultipleObjectsReturned if more than one object was found. The MultipleObjectsReturned exception is an attribute of the model class. get() raises a DoesNotExist exception if an object wasn’t found for the given parameters. This exception is also an attribute of the model class. MyTable.objects.filter(somecolumn=x) is not only usable as a list, but you can also query it again, something like MyTable.objects.filter(somecolumn=x).order_by('date'). The reason is that it's not actually a list, but a query object. You can iterate through it like through a list: for obj in MyTable.objects.filter(somecolumn=x)
1
20
0
What is the difference, please explain them in laymen's terms with examples. Thanks!
Difference between GET and FILTER in Django model layer
1.2
0
0
9,344
1,541,620
2009-10-09T03:14:00.000
8
0
1
0
python,reference,argument-passing,object-reference
1,541,625
3
true
0
0
Python does pass arguments by value but the value you are receiving is a copy of the reference (incidentally this is the exact same way that C#, VB.NET, and Java behave as well). This is the important thing to remember: Objects are not passed by reference - object references are passed by value. Since you have a copy of the reference, any operation on what that reference points to will be just as if you were holding the original reference itself.
1
1
0
This may be for most languages in general, but I'm not sure. I'm a beginner at Python and have always worked on copies of lists in C# and VB. But in Python whenever I pass a list as an argument and enumerate through using a "for i in range," and then change the value of the list argument, the input values actually changes the original list. I thought Python was supposed to pass arguments by value by default so that once the function is finished I still have the original values from before I called the function. What am I missing? Thanks!
Why Does List Argument in Python Behave Like ByRef?
1.2
0
0
1,307
1,541,722
2009-10-09T03:59:00.000
0
0
0
1
java,.net,python,web-services,google-app-engine
17,356,271
3
false
1
0
Python has a .NET alternative called IronPython. But I don't think it will work in GAE as it supports only pure python. I am also facing a similar problem trying to port a source written in C#.net into GAE compatible code. I'm going to work around it by re-inventing the spokes of the wheel (not the wheel itself) by re-doing the UI using SVG or some other method. Have you considered that?
1
3
0
Does anyone know of a .net wrapper around either python or java Google App Engine services? Any help appreciated // :)
A .net wrapper for Google App Engine?
0
0
0
3,521
1,541,776
2009-10-09T04:24:00.000
6
0
1
1
python,macos,installation,upgrade
1,541,785
7
false
0
0
May I suggest you leave the "Default" be, and install Python in /usr/local/bin. Download python Unzip it ./configure make sudo make install done. Since /usr/local/bin comes before /usr/bin in the $PATH, you will invoke 2.6 when you type python, but the OS will remain stable...
2
14
0
I'd like to upgrade the default python installation (2.5.1) supplied with OS X Leopard to the latest version. Please let me know how I can achieve this. Thanks
Upgrade Python to 2.6 on Mac
1
0
0
13,472
1,541,776
2009-10-09T04:24:00.000
20
0
1
1
python,macos,installation,upgrade
1,541,850
7
false
0
0
When an OS is distributed with some specific Python release and uses it for some OS functionality (as is the case with Mac OS X, as well as many Linux distros &c), you should not tamper in any way with the system-supplied Python (as in, "upgrading" it and the like): while Python strives for backwards compatibility within any major release (such as 2.* or 3.*, this can never be 100% guaranted; your OS supplied tested all functionality thoroughly with the specific Python version they distribute; if you manage to alter that version, "on your head be it" -- neither your OS supplier nor the PSF accepts any responsibility for whatever damage that might perhaps do to your system. Rather, as other answers already suggested, install any other release you wish "besides" the system one -- why tamper with that crucial one, and risk breaking things, when installing others is so easy anyway?! On typical Mac OS X 10.5 machines (haven't upgraded any of my several macs to 10.6 yet), I have the Apple-supplied 2.5, a 2.4 on the side to support some old projects not worth the bother to upgrate, the latest 2.6 for new stuff, 3.1 as well to get the very newest -- they all live together in peace and quiet, I just type the release number explicitly, i.e. using python2.6 at the prompt, when I want a specific release. What release gets used when at the shell prompt you just say python is up to you (I personally prefer that to mean "the system-supplied Python", but it's a matter of taste: by setting paths, or shell aliases, &c, you can make it mean whatever you wish).
2
14
0
I'd like to upgrade the default python installation (2.5.1) supplied with OS X Leopard to the latest version. Please let me know how I can achieve this. Thanks
Upgrade Python to 2.6 on Mac
1
0
0
13,472
1,543,820
2009-10-09T13:39:00.000
1
0
1
0
javascript,python,haskell,list-comprehension
1,543,985
4
false
0
0
Comprehensions is very powerful in Haskell to a large extent because Haskell is functional, so it makes extremely much sense for them to be. Python is not functional so it makes less sense. You can make a lot of complex things with comprehensions in Python but it quickly becomes hard to read, thereby defeating the whole purpose (meaning you should do it some other way). However, as pointed out here, python does allow multiple generators in comprehensions.
1
6
0
Looking at comprehensions in Python and Javascript, so far I can't see some of the main features that I consider most powerful in comprehensions in languages like Haskell. Do they allow things like multiple generators? Or are they just a basic map-filter form? If they don't allow multiple generators, I find them quite disappointing - why have such things been left out?
Comprehensions in Python and Javascript are only very basic?
0.049958
0
0
441
1,544,550
2009-10-09T15:38:00.000
1
1
0
0
python,phone-call
1,545,365
3
false
0
0
I've used Skype4Py very successfully. Keep in mind though it does require Skype to be installed and costs the standard rate for SkypeOut.
1
8
0
I'm writting a small python script notify me when certain condition met. I used smtplib which does the emailing for me, but I also want the script to call my cell phone as well. I can't find a free library for phone callings. Does anyone know any?
Is there a free python library for phone calling?
0.066568
0
0
7,113
1,545,606
2009-10-09T19:16:00.000
0
0
0
0
python,algorithm,cluster-analysis,k-means
1,545,672
8
false
0
0
You can also use GDAL, which has many many functions to work with spatial data.
1
49
1
I am looking for Python implementation of k-means algorithm with examples to cluster and cache my database of coordinates.
Python k-means algorithm
0
0
0
89,635
1,545,878
2009-10-09T20:25:00.000
6
0
1
0
python,regex
1,545,896
5
true
0
0
I'm curious as to why you are using a regular expression for this simple string replacement. The only advantage that I can see is that you can do it in one line of code instead of two, but I personally think that a replacement method is clearer than a regex for something like this. The string object has a replace method - str.replace(old, new[, count]), so use replace("-", "") and replace("\"", ""). Note that my syntax might be a little off - I'm still a python beginner.
2
1
0
I'd like to replace " and - with "" nothing! make it disappear. s = re.sub(r'[^\w\s]', '', s) this makes all punctuation disappear, but I just want those 2 characters. Thanks.
How to replace the quote " and hyphen character in a string with nothing in Python?
1.2
0
0
6,076
1,545,878
2009-10-09T20:25:00.000
1
0
1
0
python,regex
1,545,898
5
false
0
0
re.sub('[-"]', '', s)
2
1
0
I'd like to replace " and - with "" nothing! make it disappear. s = re.sub(r'[^\w\s]', '', s) this makes all punctuation disappear, but I just want those 2 characters. Thanks.
How to replace the quote " and hyphen character in a string with nothing in Python?
0.039979
0
0
6,076
1,547,365
2009-10-10T08:09:00.000
1
0
0
0
python,database,python-3.x
10,863,434
6
false
0
0
pymongo works with Python 3 now.
3
3
0
I'm coding a small piece of server software for the personal use of several users. Not hundreds, not thousands, but perhaps 3-10 at a time. Since it's a threaded server, SQLite doesn't work. It complains about threads like this: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140735085562848 and this is thread id 4301299712 Besides, they say SQLite isn't great for concurrency anyhow. Now since I started working with Python 3 (and would rather continue using it) I can't seem to get the MySQL module to work properly and others seem equally frustrated. In that case, is there any other DB option for Python 3 that I could consider?
A database for python 3?
0.033321
1
0
3,552
1,547,365
2009-10-10T08:09:00.000
0
0
0
0
python,database,python-3.x
1,547,384
6
false
0
0
You could create a new sqlite object in each thread, each using the same database file. For such a small number of users you might not come across the problems with concurrency, unless they are all writing to it very heavily.
3
3
0
I'm coding a small piece of server software for the personal use of several users. Not hundreds, not thousands, but perhaps 3-10 at a time. Since it's a threaded server, SQLite doesn't work. It complains about threads like this: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140735085562848 and this is thread id 4301299712 Besides, they say SQLite isn't great for concurrency anyhow. Now since I started working with Python 3 (and would rather continue using it) I can't seem to get the MySQL module to work properly and others seem equally frustrated. In that case, is there any other DB option for Python 3 that I could consider?
A database for python 3?
0
1
0
3,552
1,547,365
2009-10-10T08:09:00.000
0
0
0
0
python,database,python-3.x
1,550,870
6
false
0
0
Surely a pragmatic option is to just use one SQLite connection per thread.
3
3
0
I'm coding a small piece of server software for the personal use of several users. Not hundreds, not thousands, but perhaps 3-10 at a time. Since it's a threaded server, SQLite doesn't work. It complains about threads like this: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140735085562848 and this is thread id 4301299712 Besides, they say SQLite isn't great for concurrency anyhow. Now since I started working with Python 3 (and would rather continue using it) I can't seem to get the MySQL module to work properly and others seem equally frustrated. In that case, is there any other DB option for Python 3 that I could consider?
A database for python 3?
0
1
0
3,552
1,547,520
2009-10-10T09:49:00.000
1
1
0
0
python,http,soap
1,547,642
2
false
0
0
I wrote something like this in Boo, using a .Net HTTPListener, because I too had to implement someone else's defined WSDL. The WSDL I was given used document/literal form (you'll need to make some adjustments to this information if your WSDL uses rpc/encoded). I wrapped the HTTPListener in a class that allowed client code to register callbacks by SOAP action, and then gave that class a Start method that would kick off the HTTPListener. You should be able to do something very similar in Python, with a getPOST() method on BaseHTTPServer to: extract the SOAP action from the HTTP headers use elementtree to extract the SOAP header and SOAP body from the POST'ed HTTP call the defined callback for the SOAP action, sending these extracted values return the response text given by the callback in a corresponding SOAP envelope; if the callback raises an exception, catch it and re-wrap it as a SOAP fault Then you just implement a callback per SOAP action, which gets the XML content passed to it, parses this with elementtree, performs the desired action (or mock action if this is tester), and constructs the necessary response XML (I was not too proud to just create this explicitly using string interpolation, but you could use elementtree to create this by serializing a Python response object). It will help if you can get some real SOAP sample messages in order to help you not tear out your hair, especially in the part where you create the necessary response XML.
1
1
0
I need to implement a small test utility which consumes extremely simple SOAP XML (HTTP POST) messages. This is a protocol which I have to support, and it's not my design decision to use SOAP (just trying to prevent those "why do you use protocol X?" answers) I'd like to use stuff that's already in the basic python 2.6.x installation. What's the easiest way to do that? The sole SOAP message is really simple, I'd rather not use any enterprisey tools like WSDL class generation if possible. I already implemented the same functionality earlier in Ruby with just plain HTTPServlet::AbstractServlet and REXML parser. Worked fine. I thought I could a similar solution in Python with BaseHTTPServer, BaseHTTPRequestHandler and the elementree parser, but it's not obvious to me how I can read the contents of my incoming SOAP POST message. The documentation is not that great IMHO.
A minimalist, non-enterprisey approach for a SOAP server in Python
0.099668
0
1
515
1,547,526
2009-10-10T09:53:00.000
7
0
1
0
python,with-statement
1,547,628
5
true
0
0
Just use try-finally. Really, this may be nice as a mental exercise, but if you actually do it in code you care about you will end up with ugly, hard to maintain code.
2
7
0
Can you suggest a way to code a drop-in replacement for the "with" statement that will work in Python 2.4? It would be a hack, but it would allow me to port my project to Python 2.4 more nicely. EDIT: Removed irrelevant metaclass sketch
Improvizing a drop-in replacement for the "with" statement for Python 2.4
1.2
0
0
1,912
1,547,526
2009-10-10T09:53:00.000
1
0
1
0
python,with-statement
3,524,603
5
false
0
0
If you are OK with using def just to get a block, and decorators that immediately execute, you could use the function signature to get something more natural for the named case. import sys def with(func): def decorated(body = func): contexts = body.func_defaults try: exc = None, None, None try: for context in contexts: context.__enter__() body() except: exc = sys.exc_info() raise finally: for context in reversed(contexts): context.__exit__(*exc) decorated() class Context(object): def __enter__(self): print "Enter %s" % self def __exit__(self, *args): print "Exit %s(%s)" % (self, args) x = Context() @with def _(it = x): print "Body %s" % it @with def _(it = x): print "Body before %s" % it raise "Nothing" print "Body after %s" % it
2
7
0
Can you suggest a way to code a drop-in replacement for the "with" statement that will work in Python 2.4? It would be a hack, but it would allow me to port my project to Python 2.4 more nicely. EDIT: Removed irrelevant metaclass sketch
Improvizing a drop-in replacement for the "with" statement for Python 2.4
0.039979
0
0
1,912
1,548,086
2009-10-10T14:24:00.000
0
0
0
1
python,linux,ubuntu,trafficshaping
1,548,761
4
false
0
0
Is there any reason you wish to use python? As mentioned, it will likely only hand-off to already developed tools for this purpose. However, if you look around, you can find things such as Click! modular router, XORP, and others that provide a drop-in for things you want to do - not to mention all the suggestions already provided (such as iptables and tc)
1
5
0
Where can I learn about controlling/interrogating the network interface under Linux? I'd like to get specific application upload/download speeds, and enforce a speed limit for a specific application. I'd particularly like information that can help me write a traffic shaping application using Python.
Traffic shaping under Linux
0
0
0
4,040
1,548,620
2009-10-10T17:56:00.000
0
0
0
0
python
1,548,641
7
false
0
1
I started Python over a year ago too, also C++ background. I've learned that everything is simpler in Python, you don't need to worry so much if you're doing it right, you probably are. Most of the things came natural. I can't say I've read a book or anything, I usually pested the guys in #python on freenode a lot and looked at lots of other great code out there. Good luck :)
2
4
0
I have a background in C++ and Java and Objective C programming, but i am finding it hard to learn python, basically where its "Main Function" or from where the program start executing. So is there any tutorial/book which can teach python to people who have background in C++ or Java. Basically something which can show if how you were doing this in C++ and how this is done in Python. OK i think i did not put the question heading or question right, basically i was confused about the "Main" Function, otherwise other things are quite obvious from python official documentation except this concept. Thanks to all
Python for C++ or Java Programmer
0
0
0
463
1,548,620
2009-10-10T17:56:00.000
0
0
0
0
python
1,548,801
7
false
0
1
The pithiest comment I guess is that the entry point is the 1st line of your script that is not a function or a class. You don't necessarily need to use the if hack unless you want to and your script is meant to be imported.
2
4
0
I have a background in C++ and Java and Objective C programming, but i am finding it hard to learn python, basically where its "Main Function" or from where the program start executing. So is there any tutorial/book which can teach python to people who have background in C++ or Java. Basically something which can show if how you were doing this in C++ and how this is done in Python. OK i think i did not put the question heading or question right, basically i was confused about the "Main" Function, otherwise other things are quite obvious from python official documentation except this concept. Thanks to all
Python for C++ or Java Programmer
0
0
0
463
1,549,606
2009-10-11T01:42:00.000
1
0
0
0
python,django
1,549,656
2
false
1
0
Try removing the space between the rec.artist_name and the |. So you should have this: {{ rec.artist_name|safe }} That'll fix the autoescaping, but I think the other commentors are correct in saying that you're storing the %20 into the db. So you'll probably have to fix it on that end of things.
1
0
0
simple%20minds is displayed when do this: {{ rec.artist_name }} How do I remove the %20...and make it spaces? When I put | safe as a fitler, the error is: Could not parse the remainder: ' | safe' from 'active.artist_name | safe' Thanks.
Why does this happen in my template for Django?
0.099668
0
0
180
1,550,226
2009-10-11T09:06:00.000
0
0
1
0
python,setup.py,pypi
68,721,587
17
false
0
0
I have a develop egg link set up with python setup.py develop under a conda environment and with pip uninstall <packagename> the egg link is removed. At least in this scenario, pip uninstall is one way to do this.
5
894
0
I have installed a python package with python setup.py install. How do I uninstall it?
python setup.py uninstall
0
0
0
502,972
1,550,226
2009-10-11T09:06:00.000
2
0
1
0
python,setup.py,pypi
57,790,918
17
false
0
0
At {virtualenv}/lib/python2.7/site-packages/ (if not using virtualenv then {system_dir}/lib/python2.7/dist-packages/) Remove the egg file (e.g. distribute-0.6.34-py2.7.egg) If there is any from file easy-install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).
5
894
0
I have installed a python package with python setup.py install. How do I uninstall it?
python setup.py uninstall
0.023525
0
0
502,972
1,550,226
2009-10-11T09:06:00.000
6
0
1
0
python,setup.py,pypi
1,550,237
17
false
0
0
Go to your python package directory and remove your .egg file, e.g.: In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/ In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/
5
894
0
I have installed a python package with python setup.py install. How do I uninstall it?
python setup.py uninstall
1
0
0
502,972
1,550,226
2009-10-11T09:06:00.000
-1
0
1
0
python,setup.py,pypi
54,174,696
17
false
0
0
I had run python setup.py install once in my PyCharm, it installs all the packages into my conda base environment. Later when I want to remove all these packages, pip uninstall does not work. I had to delete them from /anaconda3/lib/python3.7/site-packages manually :( So I don't see the reason why they use setup.py instead of writing requirements.txt file. The requirement file can be used to install packages in virtual environment and won't mess with system python packages.
5
894
0
I have installed a python package with python setup.py install. How do I uninstall it?
python setup.py uninstall
-0.011764
0
0
502,972
1,550,226
2009-10-11T09:06:00.000
0
0
1
0
python,setup.py,pypi
48,833,480
17
false
0
0
I had run "python setup.py install" at some point in the past accidentally in my global environment, and had much difficulty uninstalling. These solutions didn't help. "pip uninstall " didn't work with "Can't uninstall 'splunk-appinspect'. No files were found to uninstall." "sudo pip uninstall " didn't work "Cannot uninstall requirement splunk-appinspect, not installed". I tried uninstalling pip, deleting the pip cache, searching my hard drive for the package, etc... "pip show " eventually led me to the solution, the "Location:" was pointing to a directory, and renaming that directory caused the packaged to be removed from pip's list. I renamed the directory back, and it didn't reappear in pip's list, and now I can reinstall my package in a virtualenv.
5
894
0
I have installed a python package with python setup.py install. How do I uninstall it?
python setup.py uninstall
0
0
0
502,972
1,552,260
2009-10-12T01:00:00.000
3
0
1
0
python,operator-overloading
1,552,285
4
false
0
0
Python's overloading is "safer" in general than C++'s -- for example, the assignment operator can't be overloaded, and += has a sensible default implementation. In some ways, though, overloading in Python is still as "broken" as in C++. Programmers should restrain the desire to "re-use" an operator for unrelated purposes, such as C++ re-using the bitshifts to perform string formatting and parsing. Don't overload an operator with different semantics from your implementation just to get prettier syntax. Modern Python style strongly discourages "rogue" overloading, but many aspects of the language and standard library retain poorly-named operators for backwards compatibility. For example: %: modulus and string formatting +: addition and sequence concatenation *: multiplication and sequence repetition So, rule of thumb? If your operator implementation will surprise people, don't do it.
2
14
0
From what I remember from my C++ class, the professor said that operator overloading is cool, but since it takes relatively a lot of thought and code to cover all end-cases (e.g. when overloading + you probably also want to overload ++ and +=, and also make sure to handle end cases like adding an object to itself etc.), you should only consider it in those cases where this feature will have a major impact on your code, like overloading the operators for the matrix class in a math application. Does the same apply to python? Would you recommend overriding operator behavior in python? And what rules of thumb can you give me?
Rules of thumb for when to use operator overloading in python
0.148885
0
0
8,475
1,552,260
2009-10-12T01:00:00.000
12
0
1
0
python,operator-overloading
1,552,267
4
false
0
0
I've written software with significant amounts of overloading, and lately I regret that policy. I would say this: Only overload operators if it's the natural, expected thing to do and doesn't have any side effects. So if you make a new RomanNumeral class, it makes sense to overload addition and subtraction etc. But don't overload it unless it's natural: it makes no sense to define addition and subtraction for a Car or a Vehicle object. Another rule of thumb: don't overload ==. It makes it very hard (though not impossible) to actually test if two objects are the same. I made this mistake and paid for it for a long time. As for when to overload +=, ++ etc, I'd actually say: only overload additional operators if you have a lot of demand for that functionality. It's easier to have one way to do something than five. Sure, it means sometimes you'll have to write x = x + 1 instead of x += 1, but more code is ok if it's clearer. In general, like with many 'fancy' features, it's easy to think that you want something when you don't really, implement a bunch of stuff, not notice the side effects, and then figure it out later. Err on the conservative side. EDIT: I wanted to add an explanatory note about overloading ==, because it seems various commenters misunderstand this, and it's caught me out. Yes, is exists, but it's a different operation. Say I have an object x, which is either from my custom class, or is an integer. I want to see if x is the number 500. But if you set x = 500, then later test x is 500, you will get False, due to the way Python caches numbers. With 50, it would return True. But you can't use is, because you might want x == 500 to return True if x is an instance of your class. Confusing? Definitely. But this is the kind of detail you need to understand to successfully overload operators.
2
14
0
From what I remember from my C++ class, the professor said that operator overloading is cool, but since it takes relatively a lot of thought and code to cover all end-cases (e.g. when overloading + you probably also want to overload ++ and +=, and also make sure to handle end cases like adding an object to itself etc.), you should only consider it in those cases where this feature will have a major impact on your code, like overloading the operators for the matrix class in a math application. Does the same apply to python? Would you recommend overriding operator behavior in python? And what rules of thumb can you give me?
Rules of thumb for when to use operator overloading in python
1
0
0
8,475
1,553,114
2009-10-12T07:06:00.000
5
0
0
0
python,algorithm
1,553,126
4
true
0
0
Why not download some real open source repos and use those? Have you thought about what goes into the files? is that random data too?
1
2
1
I'd like to profile some VCS software, and to do so I want to generate a set of random files, in randomly arranged directories. I'm writing the script in Python, but my question is briefly: how do I generate a random directory tree with an average number of sub-directories per directory and some broad distribution of files per directory? Clarification: I'm not comparing different VCS repo formats (eg. SVN vs Git vs Hg), but profiling software that deals with SVN (and eventually other) working copies and repos. The constraints I'd like are to specify the total number of files (call it 'N', probably ~10k-100k) and the maximum depth of the directory structure ('L', probably 2-10). I don't care how many directories are generated at each level, and I don't want to end up with 1 file per dir, or 100k all in one dir. The distribution is something I'm not sure about, since I don't know whether VCS' (SVN in particular) would perform better or worse with a very uniform structure or a very skewed structure. Nonetheless, it would be nice if I could come up with an algorithm that didn't "even out" for large numbers. My first thoughts were: generate the directory tree using some method, and then uniformly populate the tree with files (treating each dir equally, with no regard as to nesting). My back-of-the-envelope calcs tell me that if there are 'L' levels, with 'D' subdirs per dir, and about sqrt(N) files per dir, then there will be about D^L dirs, so N =~ sqrt(N)*(D^L) => D =~ N^(1/2L). So now I have an approximate value for 'D', how can I generate the tree? How do I populate the files? I'd be grateful just for some pointers to good resources on algorithms I could use. My searching only found pretty applets/flash.
Generate random directories/files given number of files and depth
1.2
0
0
3,603
1,554,546
2009-10-12T13:22:00.000
5
0
1
0
python,properties
1,554,639
8
false
0
0
A basic reason is really simply that it looks better. It is more pythonic. Especially for libraries. something.getValue() looks less nice than something.value In plone (a pretty big CMS), you used to have document.setTitle() which does a lot of things like storing the value, indexing it again and so. Just doing document.title = 'something' is nicer. You know that a lot is happening behind the scenes anyway.
4
81
0
It appears to me that except for a little syntactic sugar, property() does nothing good. Sure, it's nice to be able to write a.b=2 instead of a.setB(2), but hiding the fact that a.b=2 isn't a simple assignment looks like a recipe for trouble, either because some unexpected result can happen, such as a.b=2 actually causes a.b to be 1. Or an exception is raised. Or a performance problem. Or just being confusing. Can you give me a concrete example for a good usage of it? (using it to patch problematic code doesn't count ;-)
When and how to use the builtin function property() in python
0.124353
0
0
35,751
1,554,546
2009-10-12T13:22:00.000
1
0
1
0
python,properties
34,562,077
8
false
0
0
getters and setters are needed for many purposes, and are very useful because they are transparent to the code. Having object Something the property height, you assign a value as Something.height = 10, but if height has a getter and setter then at the time you do assign that value you can do many things in the procedures, like validating a min or max value, like triggering an event because the height changed, automatically setting other values in function of the new height value, all that may occur at the moment Something.height value was assigned. Remember, you don't need to call them in your code, they are auto executed at the moment you read or write the property value. In some way they are like event procedures, when the property X changes value and when the property X value is read.
4
81
0
It appears to me that except for a little syntactic sugar, property() does nothing good. Sure, it's nice to be able to write a.b=2 instead of a.setB(2), but hiding the fact that a.b=2 isn't a simple assignment looks like a recipe for trouble, either because some unexpected result can happen, such as a.b=2 actually causes a.b to be 1. Or an exception is raised. Or a performance problem. Or just being confusing. Can you give me a concrete example for a good usage of it? (using it to patch problematic code doesn't count ;-)
When and how to use the builtin function property() in python
0.024995
0
0
35,751
1,554,546
2009-10-12T13:22:00.000
15
0
1
0
python,properties
1,554,753
8
false
0
0
but hiding the fact that a.b=2 isn't a simple assignment looks like a recipe for trouble You're not hiding that fact though; that fact was never there to begin with. This is python -- a high-level language; not assembly. Few of the "simple" statements in it boil down to single CPU instructions. To read simplicity into an assignment is to read things that aren't there. When you say x.b = c, probably all you should think is that "whatever just happened, x.b should now be c".
4
81
0
It appears to me that except for a little syntactic sugar, property() does nothing good. Sure, it's nice to be able to write a.b=2 instead of a.setB(2), but hiding the fact that a.b=2 isn't a simple assignment looks like a recipe for trouble, either because some unexpected result can happen, such as a.b=2 actually causes a.b to be 1. Or an exception is raised. Or a performance problem. Or just being confusing. Can you give me a concrete example for a good usage of it? (using it to patch problematic code doesn't count ;-)
When and how to use the builtin function property() in python
1
0
0
35,751
1,554,546
2009-10-12T13:22:00.000
3
0
1
0
python,properties
1,556,870
8
false
0
0
You are correct, it is just syntactic sugar. It may be that there are no good uses of it depending on your definition of problematic code. Consider that you have a class Foo that is widely used in your application. Now this application has got quite large and further lets say it's a webapp that has become very popular. You identify that Foo is causing a bottleneck. Perhaps it is possible to add some caching to Foo to speed it up. Using properties will let you do that without changing any code or tests outside of Foo. Yes of course this is problematic code, but you just saved a lot of $$ fixing it quickly. What if Foo is in a library that you have hundreds or thousands of users for? Well you saved yourself having to tell them to do an expensive refactor when they upgrade to the newest version of Foo. The release notes have a lineitem about Foo instead of a paragraph porting guide. Experienced Python programmers don't expect much from a.b=2 other than a.b==2, but they know even that may not be true. What happens inside the class is it's own business.
4
81
0
It appears to me that except for a little syntactic sugar, property() does nothing good. Sure, it's nice to be able to write a.b=2 instead of a.setB(2), but hiding the fact that a.b=2 isn't a simple assignment looks like a recipe for trouble, either because some unexpected result can happen, such as a.b=2 actually causes a.b to be 1. Or an exception is raised. Or a performance problem. Or just being confusing. Can you give me a concrete example for a good usage of it? (using it to patch problematic code doesn't count ;-)
When and how to use the builtin function property() in python
0.07486
0
0
35,751
1,555,517
2009-10-12T16:22:00.000
1
1
0
0
php,python,nonblocking
1,555,614
6
false
0
0
What you need to do is have the PHP script execute another script that does the server call and then sends the user the request.
1
14
0
I have a two websites in php and python. When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server. Is it possible to continue running a php/python script after sending a response to the user. In that case I'll first reply to the user and only then send the HTTP POST request to the remote server. Is it possible to create a non-blocking HTTP client in php/python without handling the response at all? A solution that will have the same logic in php and python is preferable for me. Thanks
sending a non-blocking HTTP POST request
0.033321
0
1
12,400
1,555,968
2009-10-12T17:48:00.000
0
0
1
0
python,dictionary
1,556,417
4
false
0
0
If I were you and speed was a big concern, I'd probably create a new container class "DictMax" that'd keep track of it's largest non-zero value elements by having an internal stack of indexes, where the top element of the stack is always the key of the largest element in the dictionary. That way you'd get the largest element in constant time everytime.
1
7
0
I'm new Python and trying to implement code in a more Pythonic and efficient fashion. Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value? Thanks
Efficient way to find the largest key in a dictionary with non-zero value
0
0
0
22,538
1,556,668
2009-10-12T20:22:00.000
2
1
0
1
python,perl
1,557,216
8
false
0
0
Well, if you really want to write the GUI in another language (which, seriously, is just a bad idea, since it will cost you more than it could ever benefit you), the thing you should do is the following: Document your Perl app in terms of the services it provides. You should do it with XML Schema Definition - XSD - for the data types and Web Service Description Language - WSDL - for the actual service. Implement the services in Perl, possibly using Catalyst::Controller::SOAP, or just XML::Compile::SOAP. Consume the services from your whatever-language GUI interface. Profit. But honestly, I really suggest you taking a look at the Perl GTK2 binding, it is awesome, including features such as implementing a Gtk class entirely in Perl and using it as argument to a function written in C - for instance, you can write a model class for a gtk tree entirely in Perl.
3
1
0
We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codebase in the Python GUI. So... any suggestions on how achieve this? We are considering a few options: Write executables (in Perl) that mimic function calls; invoke those Perl executables in python as system calls. Write Perl executables on-the-fly inside the Python dashboard, and invoke the (temporary) Perl executable. Find some kind of Perl-to-Python converter or binding. Any other ideas? I'd love to hear if other people have confronted this problem. Unfortunately, it's not an option to convert the codebase itself to Python at this time.
Recommendations for perl-to-python interoperation?
0.049958
0
0
406
1,556,668
2009-10-12T20:22:00.000
1
1
0
1
python,perl
1,560,979
8
false
0
0
Interesting project: I would opt for loose-coupling and consider an XML-RPC or JSON based approach.
3
1
0
We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codebase in the Python GUI. So... any suggestions on how achieve this? We are considering a few options: Write executables (in Perl) that mimic function calls; invoke those Perl executables in python as system calls. Write Perl executables on-the-fly inside the Python dashboard, and invoke the (temporary) Perl executable. Find some kind of Perl-to-Python converter or binding. Any other ideas? I'd love to hear if other people have confronted this problem. Unfortunately, it's not an option to convert the codebase itself to Python at this time.
Recommendations for perl-to-python interoperation?
0.024995
0
0
406
1,556,668
2009-10-12T20:22:00.000
7
1
0
1
python,perl
1,557,825
8
false
0
0
I hate to be another one in the chorus, but... Avoid the use of an alternate language Use Wx so it's native look and feel makes the application look "real" to non-technical audiences. Download the Padre source code and see how it does Wx Perl code, then steal rampantly from it's best tricks or maybe just gut it and use the application skeleton (using the Artistic half of the Perl dual license to make it legal). Build your own Strawberry Perl subclass to package the application as an MSI installer and push it out across the corporate Active Directory domain. Of course, I only say all this because you said "Dashboard" which I read as "Corporate", which then makes me assume a Microsoft AD network...
3
1
0
We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codebase in the Python GUI. So... any suggestions on how achieve this? We are considering a few options: Write executables (in Perl) that mimic function calls; invoke those Perl executables in python as system calls. Write Perl executables on-the-fly inside the Python dashboard, and invoke the (temporary) Perl executable. Find some kind of Perl-to-Python converter or binding. Any other ideas? I'd love to hear if other people have confronted this problem. Unfortunately, it's not an option to convert the codebase itself to Python at this time.
Recommendations for perl-to-python interoperation?
1
0
0
406
1,557,972
2009-10-13T02:43:00.000
0
0
1
0
python,mysql,pylons,module,virtualenv
1,563,869
1
true
0
0
Ok Got it all figured out, After I installed the module on my normal python 2.6 install I went into my Python26 folder and low and behold I happened to find a file called MySQL-python-wininst which happened to be a list of all of the installed module files. Basicly it was two folders called MySQLdb and another called MySQL_python-1.2.2-py2.6.egg-info as well as three other files: _mysql.pyd, _mysql_exceptions.py, _mysql_exceptions.pyc. So I went into the folder where they were located (Python26/Lib/site-packages) and copied them to virtualenv's site-packages folder (env/Lib/site-packages) and the module was fully functional! Note: All paths are the defaults
1
0
0
I am doing some pylons work in a virtual python enviorment, I want to use MySQL with SQLalchemy but I can't install the MySQLdb module on my virtual enviorment, I can't use easyinstall because I am using a version that was compiled for python 2.6 in a .exe format, I tried running the install from inside the virtual enviorment but that did not work, any sugestions?
Install custom modules in a python virtual enviroment
1.2
1
0
442