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
802,578
2009-04-29T14:21:00.000
6
0
1
0
java,python,keyword,final
802,617
11
false
0
0
Python has no equivalent of "final". It doesn't have "public" and "protected" either, except by naming convention. It's not that "bondage and discipline".
2
78
0
I couldn't find documentation on an equivalent of Java's final in Python, is there such a thing? I'm creating a snapshot of an object (used for restoration if anything fails); once this backup variable is assigned, it should not be modified -- a final-like feature in Python would be nice for this.
`final` keyword equivalent for variables in Python?
1
0
0
83,113
803,566
2009-04-29T18:09:00.000
2
0
1
0
python,multithreading,deadlock,embedding
803,703
3
false
0
0
"When calling into Python, I may need to hold the same locks, because I may be iterating over some collection of objects, for example." This often indicates that a single process with multiple threads isn't appropriate. Perhaps this is a situation where multiple processes -- each with a specific object from the collection -- makes more sense. Independent process -- each with their own pool of threads -- may be easier to manage.
2
7
0
Is there any way to embed python, allow callbacks from python to C++, allowing the Pythhon code to spawn threads, and avoiding deadlocks? The problem is this: To call into Python, I need to hold the GIL. Typically, I do this by getting the main thread state when I first create the interpreter, and then using PyEval_RestoreThread() to take the GIL and swap in the thread state before I call into Python. When called from Python, I may need to access some protected resources that are protected by a separate critical section in my host. This means that Python will hold the GIL (potentially from some other thread than I initially called into), and then attempt to acquire my protection lock. When calling into Python, I may need to hold the same locks, because I may be iterating over some collection of objects, for example. The problem is that even if I hold the GIL when I call into Python, Python may give it up, give it to another thread, and then have that thread call into my host, expecting to take the host locks. Meanwhile, the host may take the host locks, and the GIL lock, and call into Python. Deadlock ensues. The problem here is that Python relinquishes the GIL to another thread while I've called into it. That's what it's expected to do, but it makes it impossible to sequence locking -- even if I first take GIL, then take my own lock, then call Python, Python will call into my system from another thread, expecting to take my own lock (because it un-sequenced the GIL by releasing it). I can't really make the rest of my system use the GIL for all possible locks in the system -- and that wouldn't even work right, because Python may still release it to another thread. I can't really guarantee that my host doesn't hold any locks when entering Python, either, because I'm not in control of all the code in the host. So, is it just the case that this can't be done?
Python embedding with threads -- avoiding deadlocks?
0.132549
0
0
1,957
803,566
2009-04-29T18:09:00.000
2
0
1
0
python,multithreading,deadlock,embedding
804,431
3
false
0
0
The code that is called by python should release the GIL before taking any of your locks. That way I believe it can't get into the dead-lock.
2
7
0
Is there any way to embed python, allow callbacks from python to C++, allowing the Pythhon code to spawn threads, and avoiding deadlocks? The problem is this: To call into Python, I need to hold the GIL. Typically, I do this by getting the main thread state when I first create the interpreter, and then using PyEval_RestoreThread() to take the GIL and swap in the thread state before I call into Python. When called from Python, I may need to access some protected resources that are protected by a separate critical section in my host. This means that Python will hold the GIL (potentially from some other thread than I initially called into), and then attempt to acquire my protection lock. When calling into Python, I may need to hold the same locks, because I may be iterating over some collection of objects, for example. The problem is that even if I hold the GIL when I call into Python, Python may give it up, give it to another thread, and then have that thread call into my host, expecting to take the host locks. Meanwhile, the host may take the host locks, and the GIL lock, and call into Python. Deadlock ensues. The problem here is that Python relinquishes the GIL to another thread while I've called into it. That's what it's expected to do, but it makes it impossible to sequence locking -- even if I first take GIL, then take my own lock, then call Python, Python will call into my system from another thread, expecting to take my own lock (because it un-sequenced the GIL by releasing it). I can't really make the rest of my system use the GIL for all possible locks in the system -- and that wouldn't even work right, because Python may still release it to another thread. I can't really guarantee that my host doesn't hold any locks when entering Python, either, because I'm not in control of all the code in the host. So, is it just the case that this can't be done?
Python embedding with threads -- avoiding deadlocks?
0.132549
0
0
1,957
805,120
2009-04-30T02:19:00.000
1
0
0
1
python
1,556,571
5
false
1
0
You can have a look at celery
2
4
0
My question is: which python framework should I use to build my server? Notes: This server talks HTTP with it's clients: GET and POST (via pyAMF) Clients "submit" "tasks" for processing and, then, sometime later, retrieve the associated "task_result" submit and retrieve might be separated by days - different HTTP connections The "task" is a lump of XML describing a problem to be solved, and a "task_result" is a lump of XML describing an answer. When a server gets a "task", it queues it for processing The server manages this queue and, when tasks get to the top, organises that they are processed. the processing is performed by a long running (15 mins?) external program (via subprocess) which is feed the task XML and which produces a "task_result" lump of XML which the server picks up and stores (for later Client retrieval). it serves a couple of basic HTML pages showing the Queue and processing status (admin purposes only) I've experimented with twisted.web, using SQLite as the database and threads to handle the long running processes. But I can't help feeling that I'm missing a simpler solution. Am I? If you were faced with this, what technology mix would you use?
Python "Task Server"
0.039979
0
0
2,958
805,120
2009-04-30T02:19:00.000
0
0
0
1
python
805,126
5
false
1
0
It seems any python web framework will suit your needs. I work with a similar system on a daily basis and I can tell you, your solution with threads and SQLite for queue storage is about as simple as you're going to get. Assuming order doesn't matter in your queue, then threads should be acceptable. It's important to make sure you don't create race conditions with your queues or, for example, have two of the same job type running simultaneously. If this is the case, I'd suggest a single threaded application to do the items in the queue one by one.
2
4
0
My question is: which python framework should I use to build my server? Notes: This server talks HTTP with it's clients: GET and POST (via pyAMF) Clients "submit" "tasks" for processing and, then, sometime later, retrieve the associated "task_result" submit and retrieve might be separated by days - different HTTP connections The "task" is a lump of XML describing a problem to be solved, and a "task_result" is a lump of XML describing an answer. When a server gets a "task", it queues it for processing The server manages this queue and, when tasks get to the top, organises that they are processed. the processing is performed by a long running (15 mins?) external program (via subprocess) which is feed the task XML and which produces a "task_result" lump of XML which the server picks up and stores (for later Client retrieval). it serves a couple of basic HTML pages showing the Queue and processing status (admin purposes only) I've experimented with twisted.web, using SQLite as the database and threads to handle the long running processes. But I can't help feeling that I'm missing a simpler solution. Am I? If you were faced with this, what technology mix would you use?
Python "Task Server"
0
0
0
2,958
805,160
2009-04-30T02:39:00.000
2
1
1
0
python,perl
805,185
3
false
0
0
You could serialize the results to some sort of a string format, print this to standard output in the Perl script. Then, from python call the perl script and redirect the results of stdout to a variable in python.
1
1
0
I have one script in Perl and the other in Python. I need to get the results of Perl in Python and then give the final report. The results from Perl can be scalar variable, hash variable, or an array. Please let me know as soon as possible regarding this.
How can I get the results of a Perl script in Python script?
0.132549
0
0
1,453
805,393
2009-04-30T05:03:00.000
0
0
0
0
python,sql,django,stored-procedures,django-models
3,675,814
7
false
1
0
I guess the improved raw sql queryset support in Django 1.2 can make this easier as you wouldn't have to roll your own make_instance type code.
2
34
0
I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django's ORM. Has anyone integrated SP's with Django's ORM successfully? If so, what RDBMS and how did you do it?
What is the best way to access stored procedures in Django's ORM
0
0
0
43,756
805,393
2009-04-30T05:03:00.000
6
0
0
0
python,sql,django,stored-procedures,django-models
806,302
7
false
1
0
Don't. Seriously. Move the stored procedure logic into your model where it belongs. Putting some code in Django and some code in the database is a maintenance nightmare. I've spent too many of my 30+ years in IT trying to clean up this kind of mess.
2
34
0
I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django's ORM. Has anyone integrated SP's with Django's ORM successfully? If so, what RDBMS and how did you do it?
What is the best way to access stored procedures in Django's ORM
1
0
0
43,756
805,720
2009-04-30T07:08:00.000
0
0
1
0
python,theory
805,801
11
false
0
0
enhance my knowledge of computers Well, what do you exactly mean by that? Python, or any other high level language, are designed to actually hide all the nasty details. That's one of the reasons, why it's apt for non-pros like (e.g. scientist). If you want to know how stuff actually work, you should learn pure C. But then again, if you're not planning to have any career related to SC, there's not much point to it. Learn some more advanced algorithms and data structures instead. That'll result you more interesting, useful and is platform- and language-agnostic.
1
10
0
I'm a newbie to programming. I had 1 semester of computer science (we used java). I got an A in the course and was able to do everything assigned, however I'm not sure I really understood it. I ignored the text and learned by looking at sample programs and then trial and error. I was ahead of the class except for two guys who came in knowing java or another OOP language. I'd like to learn Python. I'm also going to build a second PC from extra parts I have and use linux. Basically, I want to enhance my knowledge of computers. Thats my motivation. Now on learning python are there any good programming theory books that would be useful? Or should I read up on more on how computers operate on the lowest levels? I don't think I know enough to ask the question I want. I guess to make it simple, I am asking what should I know to make the most of learning python. This is not for a career. This is from a desire to know. I am no longer a computer science major (it also would not have any direct applications to my anticipated career.) I'm not looking to learn in "30 days" or "1 week" or whatever. So, starting from a very basic level is fine with me. Thanks in advance. I did a search and didn't quite find what I was looking for. UPDATE: Thanks for all the great advice. I found this site at work and couldn't find it on my home computer, so I am just getting to read now.
Newbie teaching self python, what else should I be learning?
0
0
0
3,403
805,957
2009-04-30T08:43:00.000
12
1
0
0
php,c++,python,perl,fastcgi
806,037
16
false
0
0
Using C++ is likely to result in a radically faster application than PHP, Perl or Python and somewhat faster than C# or Java - unless it spends most of its time waiting for the DB, in which case there won't be a difference. This is actually the most common case. On the other hand, due to the reasons benhoyt mentioned, developing a web app in C++ will take longer and will be harder to maintain. Furthermore, it's far more likely to contain serious security holes (nowadys everyone worries most about SQL injection and XSS - but if they were writing their webapps in C++ it would be buffer overflows and it would be their entire networks getting p0wned rather than just the data). And that's why almost nobody writes web apps in C++ these days.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
1
0
0
16,655
805,957
2009-04-30T08:43:00.000
23
1
0
0
php,c++,python,perl,fastcgi
806,004
16
true
0
0
Several years ago, I more or less learned web app programming on the job. C was the main language I knew, so I wrote the (fairly large-scale) web app in C. Bad mistake. C's string handling and memory management is tedious, and together with my lack of experience in web apps, it quickly became a hard-to-maintain project. C++ would be significantly better, mainly because std::string is much nicer than char*. However, now I'd use Python every time (though PHP is not a terrible choice, and perhaps easier to get started with). Python's string handling is awesome, and it handles Unicode seamlessly. Python has much better web tools and frameworks than C++, and its regex handling and standard libraries (urllib, email, etc) work very well. And you don't have to worry about memory management. I'd probably only use C or C++ for a web app if I was severely RAM-constrained (like on an embedded micro) or if I worked at Google and was coding a search engine that was going to have to respond to thousands of queries per second.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
1.2
0
0
16,655
805,957
2009-04-30T08:43:00.000
6
1
0
0
php,c++,python,perl,fastcgi
806,257
16
false
0
0
If you want to be able to implement web services in an existing running process (e.g. daemon), which is written in C/C++. It makes sense to make that process implement the FastCGI protocol for that interface. Get Apache to deal with HTTP (2-way SSL etc) to the outside world and field requests through FastCGI through a socket. If you do this in PHP, you have to get PHP to talk to your process, which means maintaining PHP code as well as your process.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
1
0
0
16,655
805,957
2009-04-30T08:43:00.000
2
1
0
0
php,c++,python,perl,fastcgi
806,042
16
false
0
0
You can use FastCGI with PHP/Python/Ruby/Perl to get runtime performance that should be enough until your site grows really big. And even then, you can make architectural improvements (database tuning, caching etc) to scale even more without abandoning scripting languages. Some pretty large sites are done in PHP/Python/Ruby/Perl. The big gain you get by using high-level languages is programmer performance. And that is what you should worry about first. It will be more important to respond quickly to feature demands from users, than to trim some milliseconds off the page response time.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
0.024995
0
0
16,655
805,957
2009-04-30T08:43:00.000
3
1
0
0
php,c++,python,perl,fastcgi
806,988
16
false
0
0
There is a middle ground here. Python (and I believe Perl and Ruby) allow you to call functions from C. 99 times out of 100, you won't need to. But it's nice to know that the option is there if you need it. Usually for webapps, the speed of the programming language simply isn't an issue. In the time it takes to execute a single database query, a processor can execute a few billion instructions. It's about the same for sending and receiving http data.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
0.037482
0
0
16,655
805,957
2009-04-30T08:43:00.000
7
1
0
0
php,c++,python,perl,fastcgi
806,293
16
false
0
0
The question is "where's the value created?" If you think the value is created in Memory management, careful class design and getting the nightly build to work, then use C++. You'll get to spend lots of time writing a lot of code to do important things like deleting objects that are no longer referenced. If you think the value is in deploying applications that people can use, then use Python with the Django framework. The Django tutorial shows you that within about 20 minutes you can have an application up and running. It's production-ready, and you could focus on important things: The model. Just write the model in Python, and the ORM layer handles all of the database interaction for you. No SQL. No manual mapping. The presentation. Just design your pages in HTML with a few {{}} "fill in a value here" and a few {% for thing in object_list %} constructs and your pages are ready to go. No string manipulation. The view functions. Write simple Python functions to encapsulate the processing part of your site. Not validation (those are in forms), not presentation (that was in the templates), not the underlying model (that was in the model classes), but a little bit of authorization checking, query processing and response formulation. Since Python has a rich set of collection classes, this code winds up being very short and to the point. Other stuff. URL mappings are Python regexes. Forms are matched to your model; you can subclass the defaults to add customized input validation and processing. Wonderful unit testing framework for low-level model features as well as end-to-end operations. No memory management, no scrupulous class design with abstracts and interfaces. No worrying about how to optimize string manipulation. No nightly build. Just create the stuff of real value.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
1
0
0
16,655
805,957
2009-04-30T08:43:00.000
2
1
0
0
php,c++,python,perl,fastcgi
1,470,204
16
false
0
0
Well... You will save memory and CPU power with C/C++ vs Python/Perl/Ruby/Java/.NET. If the resources saved by using C/C++ represents a large fraction of the total resources available (a FastCGI running on the embedded board of a robot), then yeah, C/C++. Else, why bother ?
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
0.024995
0
0
16,655
805,957
2009-04-30T08:43:00.000
1
1
0
0
php,c++,python,perl,fastcgi
9,231,448
16
false
0
0
C++ is a strongly typed language...i.e. you can declare ints, floats, etc....generally you can program more efficiently than you can with weakly typed languages. Facebook reported a 50% improvement when switching from PHP to C++. I would consider scripting languages to be prototyping languages...when you want production level efficiency use a compiled language.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
0.012499
0
0
16,655
805,957
2009-04-30T08:43:00.000
0
1
0
0
php,c++,python,perl,fastcgi
9,242,626
16
false
0
0
My every search through Google indicates C/C++ gives best performance for web apps that need functionality such as searching for information in web pages or getting information from a database.
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
0
0
0
16,655
805,957
2009-04-30T08:43:00.000
1
1
0
0
php,c++,python,perl,fastcgi
1,321,663
16
false
0
0
Too bad there are no benchmarks of C/C++ vs Perl CGI. Without FastCGI I think C/C++ would be a lot faster, with FastCGI possibly it'll be faster (but maybe a little less - all the initialization part is executed once). Again this is very application dependent, so some sort of benchmarks for different dynamic web pages should be provided. Personally I think that if your company has resources it should/could invest in C/C++ (given that they have to find proper ones...), otherwise is better to stick to a scripting language. Naturally if you want to deploy fast applications you should use C/C++. At the end of the day the compiled language is faster. But probably finding good C/C++ devs is hard nowdays? Cheers,
10
24
0
What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
0.012499
0
0
16,655
809,564
2009-04-30T23:25:00.000
5
1
1
0
python,unit-testing
814,552
5
true
0
0
You can't frequently run all your tests, because they're too slow. This is an inevitable consequence of your project getting bigger, and won't go away. Sure, you may be able to run the tests in parallel and get a nice speedup, but the problem will just come back later, and it'll never be as it was when your project was small. For productivity, you need to be able to code, and run relevant unit tests and get results within a few seconds. If you have a hierarchy of tests, you can do this effectively: run the tests for the module you're working on frequently, the tests for the component you're working on occasionally, and the project-wide tests infrequently (perhaps before you're thinking of checking it in). You may have integration tests, or full system tests which you may run overnight: this strategy is an extension of that idea. All you need to do to set this up is to organize your code and tests to support the hierarchy.
4
4
0
I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?
distributed/faster python unit tests
1.2
0
0
1,201
809,564
2009-04-30T23:25:00.000
3
1
1
0
python,unit-testing
811,222
5
false
0
0
See py.test, which has the ability to pass unit tests off to a group of machines, or Nose, which (as of trunk, not the currently released version) supports running tests in parallel with the multiprocessing module.
4
4
0
I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?
distributed/faster python unit tests
0.119427
0
0
1,201
809,564
2009-04-30T23:25:00.000
1
1
1
0
python,unit-testing
810,002
5
false
0
0
While coding, only run the tests of the class that You have just changed, not all the tests in the whole project. Still, it is a good practice to run all tests before You commit Your code (but the Continuous Integration server can do it for You).
4
4
0
I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?
distributed/faster python unit tests
0.039979
0
0
1,201
809,564
2009-04-30T23:25:00.000
2
1
1
0
python,unit-testing
809,629
5
false
0
0
Profile them to see what really is slow. You may be able to solve this problem with out distribution. If the tests are truly unit tests then I see not many problems with running the tests across multiple execution engines.
4
4
0
I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?
distributed/faster python unit tests
0.07983
0
0
1,201
809,737
2009-05-01T00:32:00.000
0
1
1
0
.net,tdd,ironpython
809,754
4
false
0
0
What I've found however, is that IronPython to the best of my knowledge appears to be based on Python v2, while many of the learning resources available on the web are focused on Python v3. I don't know what resources you've been looking at, but the majority of them are for v2.
1
1
0
I'm interested in learning python to have access to a more agile language for writing tests in my .NET projects. Is IronPython mature enough for these purposes yet? I'm content with writing tests in C#, but find dynamic languages like ruby and python very attractive. Would it be better to forgo IronPython while learning, and stick to the official version 3 distribution? I'd be interested to hear from anyone that has had success writing tests for a .net project in ironruby or ironpython. Edit: reworked my question to address the real issue about using dynamic languages for TDD in .NET - the version issue isn't as important. Apologies for the poorly worded question.
Learning Python on Windows for TDD
0
0
0
314
809,837
2009-05-01T01:11:00.000
1
0
0
0
python,regex,mediawiki
809,900
4
false
1
0
RegExp: \w+( \w+)+(?=]]) input [[Alexander of Paris|poet named Alexander]] output poet named Alexander input [[Alexander of Paris]] output Alexander of Paris
1
3
0
If I have some xml containing things like the following mediawiki markup: " ...collected in the 12th century, of which [[Alexander the Great]] was the hero, and in which he was represented, somewhat like the British [[King Arthur|Arthur]]" what would be the appropriate arguments to something like: re.findall([[__?__]], article_entry) I am stumbling a bit on escaping the double square brackets, and getting the proper link for text like: [[Alexander of Paris|poet named Alexander]]
Python regex for finding contents of MediaWiki markup links
0.049958
0
1
1,132
809,859
2009-05-01T01:21:00.000
-3
0
1
0
python,readability
5,759,751
13
false
0
0
I suppose 4 tab space makes the code far more readable... atleast as far as i have worked on my projects tab space of 4 has been the most comfortable option....
6
23
0
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well-reasoned arguments for the optimal size of a tab? If we want to get specific, I work mostly in python. The goal of this question is to pick a standard for the team I work on.
Optimal tab size for code readability
-0.046121
0
0
31,043
809,859
2009-05-01T01:21:00.000
1
0
1
0
python,readability
814,408
13
false
0
0
The argument for tab over spaces is that it allows each person to customize their editor to see whatever level of indentation they want. The argument against tabs is that it's difficult to spot (for the writer) when they've mixed tabs and spaces. Occasionally you will want lines that aren't indented to a tab stop, which causes mixed tabs/spaces. Using 2 spaces has these advantages: it's possible to have more nested blocks (this is important if you also have a line limit), and that using a double indent (ie 4 spaces) is nicely readable way of wrapping long lines. A disadvantage is that it's hard to judge sometimes whether two lines are at the same indent. Using 8 spaces has the opposite advantages and disadvantages to 2 spaces. It's easy to judge indent level, but you deep nesting becomes hard to manage. Many people would judge the latter disadvantage to be an advantage (because it makes deep nesting less desirable). 4 spaces is somewhere between these two extremes. But my personal belief is that it makes no difference what level of indentation you use. The most important thing is to pick some standard and stick to it. As others have said, follow PEP8 if you're writing python, follow Sun's java style guide if you're writing java, and if you're doing linux kernel hacking follow their style guide. Even if there were some small advantage in using one over the other, it's a waste of energy debating which to pick. Make a decision, and move on to the interesting part of software engineering.
6
23
0
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well-reasoned arguments for the optimal size of a tab? If we want to get specific, I work mostly in python. The goal of this question is to pick a standard for the team I work on.
Optimal tab size for code readability
0.015383
0
0
31,043
809,859
2009-05-01T01:21:00.000
4
0
1
0
python,readability
810,067
13
false
0
0
In the past I used 3 spaces. And that's still my preference. But 4 spaces seems to be the standard in the VB world. So I have switched to 4 to be in line with most code examples I see, and with the rest of my team.
6
23
0
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well-reasoned arguments for the optimal size of a tab? If we want to get specific, I work mostly in python. The goal of this question is to pick a standard for the team I work on.
Optimal tab size for code readability
0.061461
0
0
31,043
809,859
2009-05-01T01:21:00.000
0
0
1
0
python,readability
809,944
13
false
0
0
I read that 2 spaces is actually optimal, based on a study where programmers were asked to estimate the level of nesting based on indentation, but that when asked, programmers thought 4 would be optimal. Citation needed, but can't find it.
6
23
0
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well-reasoned arguments for the optimal size of a tab? If we want to get specific, I work mostly in python. The goal of this question is to pick a standard for the team I work on.
Optimal tab size for code readability
0
0
0
31,043
809,859
2009-05-01T01:21:00.000
-1
0
1
0
python,readability
809,875
13
false
0
0
I've always used one tab as two spaces.
6
23
0
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well-reasoned arguments for the optimal size of a tab? If we want to get specific, I work mostly in python. The goal of this question is to pick a standard for the team I work on.
Optimal tab size for code readability
-0.015383
0
0
31,043
809,859
2009-05-01T01:21:00.000
3
0
1
0
python,readability
809,865
13
false
0
0
I don't know of any studies that would answer your question. I don't think there is a way for this to be non-subjective but my personal preference is 4 spaces.
6
23
0
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well-reasoned arguments for the optimal size of a tab? If we want to get specific, I work mostly in python. The goal of this question is to pick a standard for the team I work on.
Optimal tab size for code readability
0.046121
0
0
31,043
810,055
2009-05-01T03:24:00.000
3
1
1
0
python
40,535,335
4
false
0
0
Python is very powerful language, Many big and the very high ranked websites are built on python.. Some big products of python are:- Google (extensively used) Youtube (extensively used) Disqus Eventbrite Pinterest Reddit Quora Mozilla Asana (extensively used) Dropbox (started with python, stayed with python) Even Many companies are shifting their websites from PHP to Python, Because of its efficiency, fast ability, and reliability, and availability of huge support and many good frameworks such as Django.. Moreover, I am not saying that PHP is not a good server side scripting language, But truth is that, most users are adapting python instead of PHP.
3
21
0
What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams. It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller. Are there some huge companies that develop primarily in Python?
Biggest python projects
0.148885
0
0
22,280
810,055
2009-05-01T03:24:00.000
12
1
1
0
python
810,240
4
false
0
0
Among many other Python-centered companies, beyond the ones already mentioned by Unknown, I'd mention big pharma firms such as Astra-Zeneca, film studios such as Lucasfilm, and research places such as NASA, Caltech, Lawrence Livermore NRL. Among the sponsors of Pycon Italia Tre (next week in Firenze, IT -- see www.pycon.it) are Qt/Trolltech (a wholly owned subsidiary of Nokia), Google of course, Statpro, ActiveState, Wingware -- besides, of course, several Italian companies. Among the sponsors of Pycon US in Chicago in March were (of course) Google, as well as Sun Microsystems, Microsoft, Slide.com, Walt Disney Animation Studios, Oracle, Canonical, VMWare -- these are all companies who thought it worthwhile to spend money in order to have visibility to experienced Pythonistas, so presumably ones making significant large-scale use of Python (and in most cases trying to hire experienced Python developers in particular).
3
21
0
What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams. It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller. Are there some huge companies that develop primarily in Python?
Biggest python projects
1
0
0
22,280
810,055
2009-05-01T03:24:00.000
8
1
1
0
python
810,992
4
false
0
0
Our project is over 30,000 lines of Python. That's probably small by some standards. But it's plenty big enough to fill my little brain. The application is mentioned in our annual report, so it's "strategic" in that sense. We're not a "huge" company, so we don't really qualify. A "huge company" (Fortune 1000?) doesn't develop primarily in any single language. Large companies will have lots of development teams, each using a different technology, depending on -- well -- on nothing in particular. When you get to "epic companies" (Fortune 10) you're looking at an organization that's very much like a conglomerate of several huge companies rolled together. Each huge company within an epic company is still a huge company with multiple uncoordinated IT shops doing unrelated things -- there's no "develop primarily in" any particular language or toolset. Even for "large companies" and "small companies" (like ours) you still have fragmentation. Our in-house IT is mostly Microsoft. Our other product development is mostly Java. My team, however, doesn't have much useful specification, so we use Python. We use python because of the duck typing and dynamic programming features. (I don't know what a dynamic type system is -- Python types are static -- when you create an object, its type can never change.) Since no huge company develops primarily in any particular language or toolset, the trivial answer to your question is "No" for any language or tool. And No for Python in particular.
3
21
0
What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams. It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller. Are there some huge companies that develop primarily in Python?
Biggest python projects
1
0
0
22,280
811,670
2009-05-01T14:41:00.000
3
0
1
0
python,windows,security,excel
811,736
5
false
0
0
Sadly, Python is not very safe in this way, and this is quite well known. Its dynamic nature combined with the very thin layer over standard OS functionality makes it hard to lock things down. Usually the best option is to ensure the user running the app has limited rights, but I expect that is not practical. Another is to run it in a virtual machine where potential damage is at least limited to that environment. Failing that, someone with knowledge of Python's C API could build you a bespoke .dll that explicitly limits the scope of that particular Python interpreter, vetting imports and file writes etc., but that would require quite a thorough inspection of what functionality you need and don't need and some equally thorough testing after the fact.
3
4
0
I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution. After some frustrating conversations with my foreign counterpart, it seems that they are concerned that somebody might misuse the python interpreter on their computer to generate non-standard applications which might be used to circumvent security. My initial suggestion was just to take away execute-rights on python.exe and pythonw.exe: Our application works as an Excel plugin which only uses the Python DLL. Those exe files are never actually used. My counterpart remained concerned that somebody could make calls against the Python DLL - a hacker could exploit the "exec" function, for example from another programming language or virtual machine capable of calling functions in Windows DLLs, for example VBA. Is there something we can do to prevent the DLL we want installed from being abused? At this point I ran out of ideas. I need to find a way to ensure that Python will only run our authorized programs. Of course, there is an element of absurdity to this question: Since the computers all have Excel and Word they all have VBA which is a well-known scripting language somewhat equivalent in capability to Python. It obviously does not make sense to worry about python when Excel's VBA is wide-open, however this is corporate politics and it's my team who are proposing to use Python, so we need to prove that our stuff can be made reasonably safe.
How can I create a locked-down python environment?
0.119427
0
0
1,040
811,670
2009-05-01T14:41:00.000
0
0
1
0
python,windows,security,excel
814,427
5
false
0
0
I agree that you should examine the regulations to see what they actually require. If you really do need a "locked down" Python DLL, here's a way that might do it. It will probably take a while and won't be easy to get right. BTW, since this is theoretical, I'm waving my hands over work that varies from massive to trivial :-). The idea is to modify Python.DLL so it only imports .py modules that have been signed by your private key. It verifies this by using the public key and a code signature stashed in a variable you add to each .py that you trust via a coding signing tool. Thus you have: Build a private build from the Python source. In your build, change the import statement to check for a code signature on every module when imported. Create a code signing tool that signs all the modules you use and assert are safe (aka trusted code). Something like __code_signature__ = "ABD03402340"; but cryptographically secure in each module's __init__.py file. Create a private/public key pair for signing the code and guard the private key. You probably don't want to sign any of the modules with exec() or eval() type capabilities. .NET's code signing model might be helpful here if you can use IronPython. I'm not sure its a great idea to pursue, but in the end you would be able to assert that your build of the Python.DLL would only run the code that you have signed with your private key.
3
4
0
I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution. After some frustrating conversations with my foreign counterpart, it seems that they are concerned that somebody might misuse the python interpreter on their computer to generate non-standard applications which might be used to circumvent security. My initial suggestion was just to take away execute-rights on python.exe and pythonw.exe: Our application works as an Excel plugin which only uses the Python DLL. Those exe files are never actually used. My counterpart remained concerned that somebody could make calls against the Python DLL - a hacker could exploit the "exec" function, for example from another programming language or virtual machine capable of calling functions in Windows DLLs, for example VBA. Is there something we can do to prevent the DLL we want installed from being abused? At this point I ran out of ideas. I need to find a way to ensure that Python will only run our authorized programs. Of course, there is an element of absurdity to this question: Since the computers all have Excel and Word they all have VBA which is a well-known scripting language somewhat equivalent in capability to Python. It obviously does not make sense to worry about python when Excel's VBA is wide-open, however this is corporate politics and it's my team who are proposing to use Python, so we need to prove that our stuff can be made reasonably safe.
How can I create a locked-down python environment?
0
0
0
1,040
811,670
2009-05-01T14:41:00.000
9
0
1
0
python,windows,security,excel
811,711
5
false
0
0
"reasonably safe" defined arbitrarily as "safer than Excel and VBA". You can't win that fight. Because the fight is over the wrong thing. Anyone can use any EXE or DLL. You need to define "locked down" differently -- in a way that you can succeed. You need to define "locked down" as "cannot change the .PY files" or "we can audit all changes to the .PY files". If you shift the playing field to something you can control, you stand a small chance of winning. Get the regulations -- don't trust anyone else to interpret them for you. Be absolutely sure what the regulations require -- don't listen to someone else's interpretation.
3
4
0
I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution. After some frustrating conversations with my foreign counterpart, it seems that they are concerned that somebody might misuse the python interpreter on their computer to generate non-standard applications which might be used to circumvent security. My initial suggestion was just to take away execute-rights on python.exe and pythonw.exe: Our application works as an Excel plugin which only uses the Python DLL. Those exe files are never actually used. My counterpart remained concerned that somebody could make calls against the Python DLL - a hacker could exploit the "exec" function, for example from another programming language or virtual machine capable of calling functions in Windows DLLs, for example VBA. Is there something we can do to prevent the DLL we want installed from being abused? At this point I ran out of ideas. I need to find a way to ensure that Python will only run our authorized programs. Of course, there is an element of absurdity to this question: Since the computers all have Excel and Word they all have VBA which is a well-known scripting language somewhat equivalent in capability to Python. It obviously does not make sense to worry about python when Excel's VBA is wide-open, however this is corporate politics and it's my team who are proposing to use Python, so we need to prove that our stuff can be made reasonably safe.
How can I create a locked-down python environment?
1
0
0
1,040
812,781
2009-05-01T19:03:00.000
28
1
0
1
python,c,compiler-construction
813,744
4
false
0
0
Use your vendor's package management to add the package that contains the development files for bz2. It's usually a package called "libbz2-dev". E.g. on Ubuntu sudo apt-get install libbz2-dev
3
28
0
It seems that Python 2.6.1 doesn't compile bz2 library by default from source. I don't have lib-dynload/bz2.so What's the quickest way to add it (without installing Python from scratch)? OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 2006 i686 GNU/Linux IIRC I used only --prefix flag.
Python's bz2 module not compiled by default
1
0
0
40,171
812,781
2009-05-01T19:03:00.000
33
1
0
1
python,c,compiler-construction
813,112
4
true
0
0
You need libbz2.so (the general purpose libbz2 library) properly installed first, for Python to be able to build its own interface to it. That would typically be from a package in your Linux distro likely to have "libbz2" and "dev" in the package name.
3
28
0
It seems that Python 2.6.1 doesn't compile bz2 library by default from source. I don't have lib-dynload/bz2.so What's the quickest way to add it (without installing Python from scratch)? OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 2006 i686 GNU/Linux IIRC I used only --prefix flag.
Python's bz2 module not compiled by default
1.2
0
0
40,171
812,781
2009-05-01T19:03:00.000
9
1
0
1
python,c,compiler-construction
6,848,047
4
false
0
0
If you happen to be trying to compile Python on RHEL5 the package is called bzip2-devel, and if you have RHN set up it can be installed with this command: yum install bzip2-devel Once that is done, you don't need either of the --enable-bz2 or --with-bz2 options, but you might need --enable-shared.
3
28
0
It seems that Python 2.6.1 doesn't compile bz2 library by default from source. I don't have lib-dynload/bz2.so What's the quickest way to add it (without installing Python from scratch)? OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 2006 i686 GNU/Linux IIRC I used only --prefix flag.
Python's bz2 module not compiled by default
1
0
0
40,171
813,114
2009-05-01T20:25:00.000
5
0
0
0
python,voip
813,139
4
false
1
0
I use twilio, very easy, very fun.
1
2
0
An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show. I want to make a temporary system (with as little as possible programming) which will: Allow me to establish a public telephone number (preferably in the UK) Allow members of the public to call in and receive a short pre-recorded message Leave a message of their own after the beep. At the end of the project I'd like to be able to download and convert the recorded audio into a format that I can edit with a free audio-editor. I do not mind paying to use a service if it means I can get away with doing less programming work. Also it's got to be reliable because once recorded it will be impossible to re-record the audio clips. Once set up the whole thing will run for at most 2 weeks. I'm a python programmer with some basic familiarity with VOIP, however I'd prefer not to set up a big complex system like Asterisk since I do not ever intend to use the system again once the project is over. Whatever I do has to be really simple and disposable. Also I have access to Linux and FreeBSD systems (no Windows, sorry). Thanks!
I want to make a temporary answerphone which records MP3s
0.244919
0
0
335
813,943
2009-05-02T01:37:00.000
8
0
0
0
python,apache2,pylons,mod-wsgi
814,005
2
true
1
0
Nginx with mod_wsgi requires the use of a non-blocking asynchronous framework and setup and isn't likely to work out of box with Pylons. I usually go with the proxy route to a stand-alone Pylons process using the PasteScript#cherrypy WSGI server (as its higher performing than the Paste#http one, though it won't recycle threads if you have leaks...). If you're set on using Apache and its your server (so you can compile and run Apache mod_wsgi), I'd suggest using that setup as its less maintenance to effectively utilize multiple cores. With a proxy setup, you'd have to use the mod_proxy_balancer with multiple paste processes to effectively utilize multiple cores/cpus. If you're deploying to someone else's Apache (shared hosting), mod_proxy is generally the easier solution as its stock in Apache 2.2 and above. Personally, I usually deploy with nginx + proxy to multiple paster processes.
1
4
0
Or should I be using a totally different server?
If I want to use a pylons app with Apache, should I use mod_wsgi or proxy to paste?
1.2
0
0
1,341
814,167
2009-05-02T04:52:00.000
-2
1
0
0
python
814,535
7
false
0
0
shutil.rmtree() is right answer, but just look at another useful function - os.walk()
1
83
0
What is the easiest way to do the equivalent of rm -rf in Python?
Easiest way to rm -rf in Python
-0.057081
0
0
31,538
814,896
2009-05-02T13:54:00.000
3
0
0
1
python,database,google-app-engine,cron
815,113
3
false
1
0
I think you'll find that snapshotting every user's state every hour isn't something that will scale well no matter what your framework. A more ordinary environment will disguise this by letting you have longer running tasks, but you'll still reach the point where it's not practical to take a snapshot of every user's data, every hour. My suggestion would be this: Add a 'last snapshot' field, and subclass the put() function of your model (assuming you're using Python; the same is possible in Java, but I don't know the syntax), such that whenever you update a record, it checks if it's been more than an hour since the last snapshot, and if so, creates and writes a snapshot record. In order to prevent concurrent updates creating two identical snapshots, you'll want to give the snapshots a key name derived from the time at which the snapshot was taken. That way, if two concurrent updates try to write a snapshot, one will harmlessly overwrite the other. To get the snapshot for a given hour, simply query for the oldest snapshot newer than the requested period. As an added bonus, since inactive records aren't snapshotted, you're saving a lot of space, too.
1
1
0
I'm developing software using the Google App Engine. I have some considerations about the optimal design regarding the following issue: I need to create and save snapshots of some entities at regular intervals. In the conventional relational db world, I would create db jobs which would insert new summary records. For example, a job would insert a record for every active user that would contain his current score to the "userrank" table, say, every hour. I'd like to know what's the best method to achieve this in Google App Engine. I know that there is the Cron service, but does it allow us to execute jobs which will insert/update thousands of records?
Google App Engine - design considerations about cron tasks
0.197375
1
0
1,473
815,313
2009-05-02T18:17:00.000
2
1
0
0
python,hash,twitter,md5
1,139,680
7
false
0
0
There are a few issues here. First, RT's are not always identical. Some people add a comment. Others change the URL for tracking. Others add in the person that they are RT'ing (which may or may not be the originator). So if you are going to hash the tweet, you need to boil it down to the meat of the tweet, and only hash that. Good luck. Above, someone mentioned that with 32-bits, you will start having collisions at about 65K tweets. Of course, you could have collisions on tweet #2. But I think the author of that comment was confused, since 2^16 = ~65K, but 2^32 = ~4 Trillion. So you have a little more room there. A better algorithm might be to try to derive the "unique" parts of the tweet, and fingerprint it. It's not a hash, it's a fingerprint of a few key words that define uniqueness.
3
2
0
In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database. What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way. My first attempt at this was by using md5 hashes. But I figured there can be hashing algorithms that are much more efficient, as security is not required.
Detecting Retweets using computationally inexpensive Python hashing algorithms
0.057081
0
0
798
815,313
2009-05-02T18:17:00.000
6
1
0
0
python,hash,twitter,md5
815,317
7
false
0
0
Do you really need to hash at all? Twitter messages are short enough (and disk space cheap enough) that it may be better to just store the whole message, rather than eating up clock cycles to hash it.
3
2
0
In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database. What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way. My first attempt at this was by using md5 hashes. But I figured there can be hashing algorithms that are much more efficient, as security is not required.
Detecting Retweets using computationally inexpensive Python hashing algorithms
1
0
0
798
815,313
2009-05-02T18:17:00.000
0
1
0
0
python,hash,twitter,md5
817,731
7
true
0
0
You are trying to hash a string right? Builtin types can be hashed right away, just do hash("some string") and you get some int. Its the same function python uses for dictonarys, so it is probably the best choice.
3
2
0
In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database. What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way. My first attempt at this was by using md5 hashes. But I figured there can be hashing algorithms that are much more efficient, as security is not required.
Detecting Retweets using computationally inexpensive Python hashing algorithms
1.2
0
0
798
815,446
2009-05-02T19:25:00.000
1
1
1
0
php,asp.net,python,webserver
815,457
5
false
0
0
Have you considered boo? It has a very configurable compiler and there are some good OSS examples out there (for example the brail view engine for Monorail & ASP.NET MVC).
2
0
0
I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following: ASP.NET PHP Python I'd prefer to implement PHP or Python because I am much more familiar with those, however I would like to implement whichever might be easiest. How would I go about adding this functionality to my server, and which of the three languages would be the easiest to implement? EDIT: this is not about what language i want to do web programing in, this is about what language i want to let people who use the server program in. I would like to be able for the server to serve applications written in either asp.net, PHP or Python.
C# Web Server: Implementing a Dynamic Language
0.039979
0
0
1,357
815,446
2009-05-02T19:25:00.000
1
1
1
0
php,asp.net,python,webserver
815,550
5
false
0
0
If you implement a cgi interface, you could use any kind of backend language. If you want to get fancy, you could consider looking into fastcgi.
2
0
0
I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following: ASP.NET PHP Python I'd prefer to implement PHP or Python because I am much more familiar with those, however I would like to implement whichever might be easiest. How would I go about adding this functionality to my server, and which of the three languages would be the easiest to implement? EDIT: this is not about what language i want to do web programing in, this is about what language i want to let people who use the server program in. I would like to be able for the server to serve applications written in either asp.net, PHP or Python.
C# Web Server: Implementing a Dynamic Language
0.039979
0
0
1,357
815,969
2009-05-03T00:14:00.000
9
0
0
0
python,distribution,probability,simpy
815,994
3
true
0
0
If you download the NumPy package, it has a function numpy.random.triangular(left, mode, right[, size]) that does exactly what you are looking for.
2
7
0
I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple as expovariate(lambda) (from random) for this distribution or do I have to code this thing?
Python, SimPy: How to generate a value from a triangular probability distribution?
1.2
0
0
4,889
815,969
2009-05-03T00:14:00.000
6
0
0
0
python,distribution,probability,simpy
816,185
3
false
0
0
Since, I was checking random's documentation from Python 2.4 I missed this: random.triangular(low, high, mode)¶ Return a random floating point number N such that low <= N <= high and with the specified mode between those bounds. The low and high bounds default to zero and one. The mode argument defaults to the midpoint between the bounds, giving a symmetric distribution. New in version 2.6.
2
7
0
I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple as expovariate(lambda) (from random) for this distribution or do I have to code this thing?
Python, SimPy: How to generate a value from a triangular probability distribution?
1
0
0
4,889
816,212
2009-05-03T03:09:00.000
14
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,248
13
true
1
1
In general it's all of these things. Memory, speed, and probably most importantly programmer familiarity. Apple has a huge investment in Objective C, Java is known by basically everyone, and C# is very popular as well. If you're trying for mass programmer appeal it makes sense to start with something popular, even if it's sort of boring. There aren't really any technical requirements stopping it. We could write a whole Ruby stack and let the programmer re-implement the slow bits in C and it wouldn't be that big of a deal. It would be an investment for whatever company is making the mobile OS, and at the end of the day I'm not sure they gain as much from this. Finally, it's the very beginning of mobile devices. In 5 years I wouldn't be at all surprised to see a much wider mobile stack.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
1.2
0
0
3,120
816,212
2009-05-03T03:09:00.000
0
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
817,560
13
false
1
1
webOS -- the new OS from Palm, which will debut on the Pre -- has you write apps against a webkit runtime in JavaScript. Time will tell how successful it is, but I suspect it will not be the first to go down this path. As mobile devices become more powerful, you'll see dynamic languages become more prevalent.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0
0
0
3,120
816,212
2009-05-03T03:09:00.000
0
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,228
13
false
1
1
Memory is also a significant factor. It's easy to eat memory in Python, unfortunately.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0
0
0
3,120
816,212
2009-05-03T03:09:00.000
0
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
1,077,315
13
false
1
1
There is a linux distribution for OpenMoko Freerunner called SHR. Most of its settings and framework code is written in python and... well, it isn't very fast. It is bearable, but it was planned from the beginning to rewrite it in Vala. On the other side, my few smallish apps work fast enough (with the only drawback having big startup time) to consider python to develop user applications. For the record: Freerunner has ARM-something 400MHz and 128MB of RAM. I guess that once mobile devices cross 1GHz, languages like Python will be fast enough for middle-level stuff too (the low-level being the kernel).
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0
0
0
3,120
816,212
2009-05-03T03:09:00.000
1
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,225
13
false
1
1
I think that performance concerns may be part of, but not all of, the reason. Mobile devices do not have very powerful hardware to work with. I am partly unsure about this, though.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0.015383
0
0
3,120
816,212
2009-05-03T03:09:00.000
1
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,233
13
false
1
1
One of the most pressing matters is garbage collection. Garbage collection often times introduce unpredictable pauses in embedded machines which sometimes need real time performance. This is why there is a Java Micro Edition which has a different garbage collector which reduces pauses in exchange for a slower program. Refcounting garbage collectors (like the one in CPython) are also less prone to pauses but can explode when data with many nested pointers (like a linked list) get deleted.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0.015383
0
0
3,120
816,212
2009-05-03T03:09:00.000
0
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,266
13
false
1
1
There are many reasons. Among them: business reasons, such as software lock-in strategies, efficiency: dynamic languages are usually perceived to be slower (and in some cases really are slower, or at least provide a limit to the amount of optimsation you can do. On a mobile device, optimising code is necessary much more often than on a PC), and tend to use more memory, which is a significant issue on portable devices with limited memory and little cache,, keeping development simple: a platform that supports say Python and Ruby and Java out of the box: means thrice the work to write documentation and provide support, divides development effort into three; it takes longer for helpful material to appear on the web and there are less developers who use the same language as you on your platform, requires more storage on the device to support all these languages, management need to be convinced. I've always felt that the merits of Java are easily explained to a non-technical audience. .Net and Obj-C also seem a very natural choice for a Microsoft and Apple platform, respectively.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0
0
0
3,120
816,212
2009-05-03T03:09:00.000
1
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,219
13
false
1
1
Jailbroken iPhones can have python installed, and I actually use python very frequently on mine.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0.015383
0
0
3,120
816,212
2009-05-03T03:09:00.000
0
1
0
0
python,ruby,mobile,operating-system,dynamic-languages
816,217
13
false
1
1
I suspect the basic reason is a combination of security and reliability. You don't want someone to be easily able to hack the phone, and you want to have some control over what's being installed.
9
10
0
I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language. What would be the reasoning behind a mobile OS being written in Python, Ruby, or any other dynamic language? I understand that at a low level they would not cut it but C or C++ would be fine for that and Python, for example, could be the layer on top to interact with it. I mean, there is Jython or CPython. I was just wondering why we do not see more dynamic language support in today's mobile OS's.
Python/Ruby as mobile OS
0
0
0
3,120
816,623
2009-05-03T09:02:00.000
23
0
1
0
python-3.x,setuptools
1,547,401
3
true
0
0
Setuptools 0.7 and later supports Python 3. Setuptools was in practice unmaintained for a long time, and this prompted several people to join together and make a fork, called "Distribute", which was ported to Python 3 since 2009. However in 2013 the projects merged, and Setuptools and Distribute are now the same thing. Installing Distribute will install an empty package that does nothing but install Setuptools.
1
5
0
I was trying to install "setuptool" package for python3.0. But unfortunately while I try to install it says module names "dist" is missing. pls help me to resolve this issue. EDIT AS OF MARCH 2013: please look below the accepted answer for a more upto date response by @LennartRegebro
setuptools on python3.0
1.2
0
0
14,591
816,704
2009-05-03T09:51:00.000
3
0
0
0
python,selenium
827,891
5
false
1
0
To do this the way you want (to actually capture the content sent down to the browser) you'd need to modify Selenium RC's proxy code (see ProxyHandler.java) and store the files locally on the disk in parallel to sending the response back to the browser.
2
9
0
i'm trying to save an image from a website using selenium server & python client. i know the image's URL, but i can't find the code to save it, either when it's the the document itself, or when it's embedded in the current browser session. the workaround i found so far is to save the page's screenshot (there are 2 selenium methods for doing just that), but i want the original image. i don't mind fiddling with the clicking menu options etc. but i couldn't found how. thanks
save an image with selenium & firefox
0.119427
0
1
9,916
816,704
2009-05-03T09:51:00.000
-1
0
0
0
python,selenium
816,777
5
false
1
0
How about going to the image URL and then taking a screenshot of the page? Firefox displays the image in full screen. Hope this helps..
2
9
0
i'm trying to save an image from a website using selenium server & python client. i know the image's URL, but i can't find the code to save it, either when it's the the document itself, or when it's embedded in the current browser session. the workaround i found so far is to save the page's screenshot (there are 2 selenium methods for doing just that), but i want the original image. i don't mind fiddling with the clicking menu options etc. but i couldn't found how. thanks
save an image with selenium & firefox
-0.039979
0
1
9,916
817,882
2009-05-03T20:11:00.000
1
0
0
0
python,session
817,940
5
false
0
0
It can be as simple as creating a random number. Of course, you'd have to store your session IDs in a database or something and check each one you generate to make sure it's not a duplicate, but odds are it never will be if the numbers are large enough.
1
46
0
How do I generate a unique session id in Python?
Unique session id in python
0.039979
0
0
42,141
817,884
2009-05-03T20:12:00.000
0
0
1
0
python,dictionary
817,902
5
false
0
0
Just create a subclass of dict and add the keys in the init method. class MyClass(dict) def __init__(self): """Creates a new dict with default values"""" self['key1'] = 'value1' Remember though, that in python any class that 'acts like a dict' is usually treated like one, so you don't have to worry too much about it being a subclass, you could instead implement the dict methods, although the above approach is probably more useful to you :).
1
4
0
In python, is there a way to create a class that is treated like a dictionary but have the keys pre-defined when a new instance is created?
Creating dictionaries with pre-defined keys
0
0
0
6,985
818,402
2009-05-04T00:20:00.000
3
1
0
0
python,cgi
818,405
6
false
1
0
Yes. Allow them to script their client, not your server.
4
12
0
I understand that letting any anonymous user upload any sort of file in general can be dangerous, especially if it's code. However, I have an idea to let users upload custom AI scripts to my website. I would provide the template so that the user could compete with other AI's in an online web game I wrote in Python. I either need a solution to ensure a user couldn't compromise any other files or inject malicious code via their uploaded script or a solution for client-side execution of the game. Any suggestions? (I'm looking for a solution that will work with my Python scripts)
Letting users upload Python scripts for execution
0.099668
0
0
1,115
818,402
2009-05-04T00:20:00.000
4
1
0
0
python,cgi
818,558
6
false
1
0
Along with other safeguards, you can also incorporate human review of the code. Assuming part of the experience is reviewing other members' solutions, and everyone is a python developer, don't allow new code to be activated until a certain number of members vote for it. Your users aren't going to approve malicious code.
4
12
0
I understand that letting any anonymous user upload any sort of file in general can be dangerous, especially if it's code. However, I have an idea to let users upload custom AI scripts to my website. I would provide the template so that the user could compete with other AI's in an online web game I wrote in Python. I either need a solution to ensure a user couldn't compromise any other files or inject malicious code via their uploaded script or a solution for client-side execution of the game. Any suggestions? (I'm looking for a solution that will work with my Python scripts)
Letting users upload Python scripts for execution
0.132549
0
0
1,115
818,402
2009-05-04T00:20:00.000
1
1
0
0
python,cgi
819,227
6
false
1
0
PyPy is probably a decent bet on the server side as suggested, but I'd look into having your python backend provide well defined APIs and data formats and have the users implement the AI and logic in Javascript so it can run in their browser. So the interaction would look like: For each match/turn/etc, pass data to the browser in a well defined format, provide a javascript template that receives the data and can implement logic, and provide web APIs that can be invoked by the client (browser) to take the desired actions. That way you don't have to worry about security or server power.
4
12
0
I understand that letting any anonymous user upload any sort of file in general can be dangerous, especially if it's code. However, I have an idea to let users upload custom AI scripts to my website. I would provide the template so that the user could compete with other AI's in an online web game I wrote in Python. I either need a solution to ensure a user couldn't compromise any other files or inject malicious code via their uploaded script or a solution for client-side execution of the game. Any suggestions? (I'm looking for a solution that will work with my Python scripts)
Letting users upload Python scripts for execution
0.033321
0
0
1,115
818,402
2009-05-04T00:20:00.000
0
1
0
0
python,cgi
878,455
6
true
1
0
Have an extensive API for the users and strip all other calls upon upload (such as import statements). Also, strip everything that has anything to do with file i/o. (You might want to do multiple passes to ensure that you didn't miss anything.)
4
12
0
I understand that letting any anonymous user upload any sort of file in general can be dangerous, especially if it's code. However, I have an idea to let users upload custom AI scripts to my website. I would provide the template so that the user could compete with other AI's in an online web game I wrote in Python. I either need a solution to ensure a user couldn't compromise any other files or inject malicious code via their uploaded script or a solution for client-side execution of the game. Any suggestions? (I'm looking for a solution that will work with my Python scripts)
Letting users upload Python scripts for execution
1.2
0
0
1,115
818,458
2009-05-04T01:03:00.000
0
0
0
0
python,tkinter
818,490
10
false
0
1
You have the source for idle. That shows useful tkinter code.
3
2
0
I'm beginner for the GUI programing using Tkinter, so who can tell me some useful sample codes which contains some useful codes.
How can I begin with Tkinter?
0
0
0
1,839
818,458
2009-05-04T01:03:00.000
3
0
0
0
python,tkinter
7,546,018
10
false
0
1
I used Manning's book on Tkinter, as someone else mentioned. The tutorials are very thorough, and you quickly get into the habit of thinking like a GUI coder. The New Mexico Tech worksheet is useful as a reference, but a bit too clumsy for a first resource.
3
2
0
I'm beginner for the GUI programing using Tkinter, so who can tell me some useful sample codes which contains some useful codes.
How can I begin with Tkinter?
0.059928
0
0
1,839
818,458
2009-05-04T01:03:00.000
2
0
0
0
python,tkinter
1,035,813
10
false
0
1
Mark Lutz's tome Programming Python deals at length with Tkinter. The Introduction to Tkinter ( effbot.org) and Tkinter reference: a GUI for Python (John Shipman, New Mexico Tech) are good summaries of the major features. I have read that the Tk/Tcl manual is a good reference but that might be for later.
3
2
0
I'm beginner for the GUI programing using Tkinter, so who can tell me some useful sample codes which contains some useful codes.
How can I begin with Tkinter?
0.039979
0
0
1,839
818,752
2009-05-04T04:10:00.000
1
0
0
0
php,python,mysql
818,763
4
false
0
0
Working on something you care about is the best way to learn programming, so I think this is a great idea. I also recommend Python as a place to start. Have fun!
1
2
0
So, I've been tossing this idea around in my head for a while now. At its core, it's mostly a project for me to learn programming. The idea is that, I have a large set of data, my music collection. There are quite a few datasets that my music has. Format, artist, title, album, genre, length, year of release, filename, directory, just to name a few. Ideally, I'd like to create a database that has all of this data stored in it, and in the future, create a web interface on top of it that I can manage my music collection with. So, my questions are as follows: Does this sound like a good project to begin building databases from scratch with? What language would you recommend I start with? I know tidbits of PHP, but I would imagine it would be awful to index data in a filesystem with. Python was the other language I was thinking of, considering it's the language most people consider as a beginner language. If you were going to implement this kind of system (the web interface) in your home (if you had PCs connected to a couple of stereos in your home and this was the software connected), what kind of features would you want to see? My idea for building up the indexing script would be as follows: Get it to populate the database with only the filenames From the extension of the filename, determine format Get file size Using the filenames in the database as a reference, pull ID3 or other applicable metadata (artist, track name, album, etc) Check if all files still exist on disk, and if not, flag the file as unavailable Another script would go in later and check if the files are back, if they are not, the will remove the row from the database.
Web-Based Music Library (programming concept)
0.049958
1
0
2,085
818,942
2009-05-04T06:04:00.000
4
0
0
0
python,user-interface,cross-platform,wxpython
819,026
4
true
0
1
The appearance of a dialog can change only if you use stock dialogs (like wx.FileDialog), if you make your own the layout will stay the same on every platform. wx.Dialog has a CreateStdDialogButtonSizer method that creates a wx.StdDialogButtonSizer with standard buttons where you might see differences in layout on different platforms but you don't have to use that.
3
2
0
I'm learning wxPython so most of the libraries and classes are new to me. I'm creating a Preferences dialog class but don't know the best way to make sure the OK/Cancel (or Save/Close) buttons are in the correct order for the platform. This program is intended to run both on GNOME and Windows, so I want to make sure that the buttons are in the correct order for each platform. Does wxPython provide functionality that prevents me from doing a if platform.system() == 'Linux' kind of hack?
WxPython: Cross-Platform Way to Conform Ok/Cancel Button Order
1.2
0
0
1,095
818,942
2009-05-04T06:04:00.000
0
0
0
0
python,user-interface,cross-platform,wxpython
819,330
4
false
0
1
There's the GenericMessageDialog widget that should do the right thing depending on the platform (but I've never used it so I'm not sure it does). See the wxPython demo. You can also use the SizedControls addon library (it's part of wxPython). The SizedDialog class helps to create dialogs that conform to the Human Interface Guidelines of each platform. See the wxPython demo.
3
2
0
I'm learning wxPython so most of the libraries and classes are new to me. I'm creating a Preferences dialog class but don't know the best way to make sure the OK/Cancel (or Save/Close) buttons are in the correct order for the platform. This program is intended to run both on GNOME and Windows, so I want to make sure that the buttons are in the correct order for each platform. Does wxPython provide functionality that prevents me from doing a if platform.system() == 'Linux' kind of hack?
WxPython: Cross-Platform Way to Conform Ok/Cancel Button Order
0
0
0
1,095
818,942
2009-05-04T06:04:00.000
0
0
0
0
python,user-interface,cross-platform,wxpython
819,110
4
false
0
1
If you're going to use wx (or any other x-platform toolkit) you'd better trust that it does the right thing, mon!-)
3
2
0
I'm learning wxPython so most of the libraries and classes are new to me. I'm creating a Preferences dialog class but don't know the best way to make sure the OK/Cancel (or Save/Close) buttons are in the correct order for the platform. This program is intended to run both on GNOME and Windows, so I want to make sure that the buttons are in the correct order for each platform. Does wxPython provide functionality that prevents me from doing a if platform.system() == 'Linux' kind of hack?
WxPython: Cross-Platform Way to Conform Ok/Cancel Button Order
0
0
0
1,095
819,217
2009-05-04T08:08:00.000
6
1
0
0
python,cgi
819,618
2
false
0
0
This is a really bad design idea. Your script should be designed to work independently of how it's called. The calling programs should provide a uniform environment. You'll be happiest if you design your scripts to work in exactly one consistent way. Build things like this. myscript.py - the "real work" - defined in functions and classes. myscript_cgi.py - a CGI interface that imports myscript and uses the classes and functions. myscript_cli.py - the command-line interface that parses the command-line options, imports myscript, and uses the classes and functions. A single script that does all three things (real work, cgi interface, cli interface) is usually a mistake.
1
3
0
I have one Python module that can be called by a CGI script (passing it information from a form) or from the command line (passing it options and arguments from the command line). Is there a way to establish if the module has been called from the CGI script or from the command line ??
Python, who is calling my python module
1
0
0
308
819,355
2009-05-04T08:59:00.000
2
0
0
0
python,networking,ip-address,cidr
10,053,031
28
false
0
0
#This works properly without the weird byte by byte handling def addressInNetwork(ip,net): '''Is an address in a network''' # Convert addresses to host order, so shifts actually make sense ip = struct.unpack('>L',socket.inet_aton(ip))[0] netaddr,bits = net.split('/') netaddr = struct.unpack('>L',socket.inet_aton(netaddr))[0] # Must shift left an all ones value, /32 = zero shift, /0 = 32 shift left netmask = (0xffffffff << (32-int(bits))) & 0xffffffff # There's no need to mask the network address, as long as its a proper network address return (ip & netmask) == netaddr
1
123
0
Given an ip address (say 192.168.0.1), how do I check if it's in a network (say 192.168.0.0/24) in Python? Are there general tools in Python for ip address manipulation? Stuff like host lookups, ip adddress to int, network address with netmask to int and so on? Hopefully in the standard Python library for 2.5.
How can I check if an ip is in a network in Python?
0.014285
0
1
174,240
820,742
2009-05-04T16:11:00.000
1
0
1
0
python,string,multiple-inheritance,immutability
820,750
5
false
0
0
Perhaps a custom class that contains a string would be a better approach. Do you really need to pass all string methods through to the underlying string? Why not expose the string via a property and allow consumers of the class to do whatever they wish to it?
2
6
0
I want a string with one additional attribute, let's say whether to print it in red or green. Subclassing(str) does not work, as it is immutable. I see the value, but it can be annoying. Can multiple inheritence help? I never used that. Inheriting only object and using self.value=str means I have to implement all string-ness messages (like strip) myself. Or is there a way to forward them, like Ruby's missing_method? I think using a class-level dictionary indexed by instance to store the color could work. Too ugly?
How to bestow string-ness on my class?
0.039979
0
0
1,664
820,742
2009-05-04T16:11:00.000
0
0
1
0
python,string,multiple-inheritance,immutability
820,767
5
false
0
0
You need all of string's methods, so extend string and add your extra details. So what if string is immutable? Just make your class immutable, too. Then you're creating new objects anyway so you won't accidentally mess up thinking that it's a mutable object. Or, if Python has one, extend a mutable variant of string. I'm not familiar enough with Python to know if such a structure exists.
2
6
0
I want a string with one additional attribute, let's say whether to print it in red or green. Subclassing(str) does not work, as it is immutable. I see the value, but it can be annoying. Can multiple inheritence help? I never used that. Inheriting only object and using self.value=str means I have to implement all string-ness messages (like strip) myself. Or is there a way to forward them, like Ruby's missing_method? I think using a class-level dictionary indexed by instance to store the color could work. Too ugly?
How to bestow string-ness on my class?
0
0
0
1,664
822,195
2009-05-04T21:39:00.000
1
0
1
0
python,emacs,pabbrev
14,367,349
3
false
0
0
How is this for a late response? This should work out of the box now, thanks to a patch from Trey. Binding tab in the way that pabbrev.el is somewhat naughty, but what are you to do if you want rapid expansion.
1
3
0
Normally when you hit tab on an empty line in emacs python mode it will cycle through the available tab indentations. When I hit tab when the point is at the deepest indent level I get the pabbrev buffer containing the last best match options. Does anyone else have this problem, is there an easy way around it without writing any elisp? EDIT: Trey, I want to keep pabbrev working in python mode not turn it off. So lets say there are 2 indent levels, either none, or 1 level normally if it hit tab 3 times the first would put the point at 4 spaces in (or whatever indent is set to), the second back to 0 spaces, and the third back to 4 spaces. With pabbrev mode on one indent puts the mark 4 spaces, the second brings up a buffer for autocomplete. This should not happen if there is no letters to the left of my point. Does that make any more sense?
Emacs Pabbrev and Python
0.066568
0
0
554
823,103
2009-05-05T02:52:00.000
1
1
1
0
python,profiling
823,117
4
false
0
0
What if you monkey-patched object's class or another prototypical object? This might not be the easiest if you're not using new-style classes.
1
3
0
Python is so dynamic that it's not always clear what's going on in a large program, and looking at a tiny bit of source code does not always help. To make matters worse, editors tend to have poor support for navigating to the definitions of tokens or import statements in a Python file. One way to compensate might be to write a special profiler that, instead of timing the program, would record the runtime types and paths of objects of the program and expose this data to the editor. This might be implemented with sys.settrace() which sets a callback for each line of code and is how pdb is implemented, or by using the ast module and an import hook to instrument the code, or is there a better strategy? How would you write something like this without making it impossibly slow, and without runnning afoul of extreme dynamism e.g side affects on property access?
What's the best way to record the type of every variable assignment in a Python program?
0.049958
0
0
235
825,694
2009-05-05T16:17:00.000
1
0
0
0
python,dns,hostname
828,397
3
false
1
0
Your algorithm is the right one. Since zone cuts are not reflected in the domain name (you see domain cuts - the dots - but not zone cuts), it is the only correct one. An approximate algorithm is to use a list of zones, like the one mentioned by Alnitak. Remember that these static lists are not authoritative, they lack many registries, they are stale, etc.
1
18
0
Is there a programatic way to find the domain name from a given hostname? given -> www.yahoo.co.jp return -> yahoo.co.jp The approach that works but is very slow is: split on "." and remove 1 group from the left, join and query an SOA record using dnspython when a valid SOA record is returned, consider that a domain Is there a cleaner/faster way to do this without using regexps?
Extract domain name from a host name
0.066568
0
0
14,503
825,724
2009-05-05T16:22:00.000
0
0
0
0
linux,ubuntu,wxpython
876,524
1
true
0
1
Robin Dunn himself told me that It's using the "native" GTK file dialog, just like the other apps, so there isn't anything that wx can do about it. So as a workaround I ended up installing gvfs-fuse and browsing the network through $HOME/.gvfs.. A bit klunky but it works.
1
1
0
I'm using wx.FileDialog in a wxPython 2.8.8.0 application, under Xubuntu 8.10.. My problem is that this dialog isn't network-aware, so I can't browse Samba shares. I see that this problem plagues other applications too (Firefox, Audacious...) so I'd like to ask where I could find informations on how to make it work. Is that dialog supposed to be already network-aware? Am I missing something? Some library maybe? Or should I write my own implementation? Many thanks!
Network-aware wx.FileDialog
1.2
0
1
276
825,909
2009-05-05T17:01:00.000
8
1
1
0
python,exception-handling,try-catch,runtime-error
826,144
6
true
0
0
I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there any way to differentiate between this RuntimeError and others that might be raised? If the error is caused by a specific condition, then I think the easiest way to catch the error is to test for the condition, and you can raise a more specific error yourself. After all the 'error' exists before the error is thrown, since in this case its a problem with the environment. I agree with those above - text matching on an error is kind of a terrifying prospect.
1
8
0
I'm importing a module which raises the following error in some conditions: RuntimeError: pyparted requires root access I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there any way to differentiate between this RuntimeError and others that might be raised?
Catch only some runtime errors in Python
1.2
0
0
24,955
826,724
2009-05-05T20:14:00.000
3
0
0
1
python,google-app-engine,google-cloud-datastore,custompaging
827,149
2
true
1
0
There is no efficient way to do this - in any DBMS. In every case, you have to at least read sequentially through the index records until you find the nth one, then look up the corresponding data record. This is more or less what fetch(count, offset) does in GAE, with the additional limitation of 1000 records. A better approach to this is to keep a 'bookmark', consisting of the value of the field you're ordering on for the last entity you retrieved, and the entity's key. Then, when you want to continue from where you left off, you can add the field's value as the lower bound of an inequality query, and skip records until you match or exceed the last one you saw. If you want to provide 'friendly' page offsets to users, what you can do is to use memcache to store an association between a start offset and a bookmark (order_property, key) tuple. When you generate a page, insert or update the bookmark for the entity following the last one. When you fetch a page, use the bookmark if it exists, or generate it the hard way, by doing queries with offsets - potentially multiple queries if the offset is high enough.
1
1
0
Suppose that I have the model Foo in GAE and this query: query = Foo.all().order('-key') I want to get the n-th record. What is the most efficient way to achieve that? Will the solution break if the ordering property is not unique, such as the one below: query = Foo.all().order('-color') edit: n > 1000 edit 2: I want to develop a friendly paging mechanism that shows pages available (such as Page 1, Page 2, ... Page 185) and requires a "?page=x" in the query string, instead of a "?bookmark=XXX". When page = x, the query is to fetch the records beginning from the first record of that page.
how to get the n-th record of a datastore query
1.2
0
0
845
827,295
2009-05-05T22:56:00.000
2
1
0
0
python,unit-testing,dbus,hal
827,391
2
true
0
0
If you can not mock the environment then it's probably impossible for you to write the test. If your access to HAL/D-Bus is via an object and you provide a mock instance to your test then it should be possible to emulate the necessary inputs to your test from the mock implementation.
1
2
0
How does one test a method that does some interactions with the local D-Bus (accessing a HAL object)? Results of tests will differ depending on the system that the test is run on, so I don't know how to provide the method reliable input. I'm working in Python, by the way.
Unit testing for D-Bus and HAL?
1.2
0
0
441
827,415
2009-05-05T23:39:00.000
1
0
0
0
python,django,web-applications,unicode,pylons
1,440,981
4
false
1
0
Using Unicode internally is a good way to avoid problems with non-ASCII characters. Convert at the boundaries of your application (incoming data to unicode, outgoing data to UTF-8 or whatever). Pylons can do the conversion for you in many cases: e.g. controllers can safely return unicode strings; SQLAlchemy models may declare Unicode columns. Regarding string literals in your source code: the u prefix is usually not necessary. You can safely mix str objects containing ASCII with unicode objects. Just make sure all your string literals are either pure ASCII or are u"unicode".
2
6
0
I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea. On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. What will be a problem if I don't do this? Are there any issues that will come up if I do do this? I'm using Pylons right now as my framework.
Should my python web app use unicode for all strings?
0.049958
0
0
806
827,415
2009-05-05T23:39:00.000
3
0
0
0
python,django,web-applications,unicode,pylons
829,155
4
false
1
0
What will be a problem if I don't do this? I'm a westerner living in Japan, so I've seen first-hand what is needed to work with non-ASCII characters. The problem if you don't use Unicode strings is that your code will be a frustration to the parts of the world that use anything other than A-Z. Our company has had a great deal of frustration getting certain web software to do Japanese characters without making a total mess of it. It takes a little effort for English speakers to appreciate how great Unicode is, but it really is a terrific bit of work to make computers accessible to all cultures and languages. "Gotchas": Make sure your output web pages state the encoding in use properly (e.g. using content-encoding header), and then encode all Unicode strings properly at output. Python 3 Unicode strings is a great improvement to do this right. Do everything with Unicode strings, and only convert to a specific encoding at the last moment, when doing output. Other languages, such as PHP, are prone to bugs when manipulating Unicode in e.g. UTF-8 form. Say you have to truncate a Unicode string. If it's in UTF-8 form internally, there's a risk you could chop off a multi-byte character half-way through, resulting in rubbish output. Python's use of Unicode strings internally makes it harder to make these mistakes.
2
6
0
I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea. On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. What will be a problem if I don't do this? Are there any issues that will come up if I do do this? I'm using Pylons right now as my framework.
Should my python web app use unicode for all strings?
0.148885
0
0
806
828,702
2009-05-06T08:56:00.000
2
0
0
0
python,django,postgresql,caching,memcached
828,826
5
false
1
0
Short answer : If you have enougth ram, memcached will be always faster. You can't really benchhmark memcached vs. database cache, just keep in mind that the big bottleneck with servers is disk access, specially write access. Anyway, disk cache is better if you have many objects to cache and long time expiration. But for this situation, if you want gig performances, it is better to generate your pages statically with a python script and deliver them with ligthtpd or nginx. For memcached, you could adjust the amount of ram dedicated to the server.
3
5
0
I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db. I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I would like to know exactly what would be the benefits of such a change: I imagine that my site may be just not big enough for the better cache backend to make a difference. The point is: it wouldn't be me who would be installing and configuring memcached, and I don't want to waste somebody's time for nothing or very little. How can I measure the overhead introduced by using the db as the cache backend? I've looked at django-debug-toolbar, but if I understand correctly it isn't something you'd like to put on a production site (you have to set DEBUG=True for it to work). Unfortunately, I cannot quite reproduce the production setting on my laptop (I have a different OS, CPU and a lot more RAM). Has anyone benchmarked different Django cache/session backends? Does anybody know what would be the performance difference if I was doing, for example, one session-write on every request?
How to measure Django cache performance?
0.07983
0
0
3,032
828,702
2009-05-06T08:56:00.000
0
0
0
0
python,django,postgresql,caching,memcached
2,105,437
5
false
1
0
Just try it out. Use firebug or a similar tool and run memcache with a bit of RAM allocation (e.g. 64mb) on the test server. Mark your average loading results seen in firebug without memcache, then turn caching on and mark new results. That's done as easy as it said. The results usually shocks people, because the perfomance raises up very nicely.
3
5
0
I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db. I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I would like to know exactly what would be the benefits of such a change: I imagine that my site may be just not big enough for the better cache backend to make a difference. The point is: it wouldn't be me who would be installing and configuring memcached, and I don't want to waste somebody's time for nothing or very little. How can I measure the overhead introduced by using the db as the cache backend? I've looked at django-debug-toolbar, but if I understand correctly it isn't something you'd like to put on a production site (you have to set DEBUG=True for it to work). Unfortunately, I cannot quite reproduce the production setting on my laptop (I have a different OS, CPU and a lot more RAM). Has anyone benchmarked different Django cache/session backends? Does anybody know what would be the performance difference if I was doing, for example, one session-write on every request?
How to measure Django cache performance?
0
0
0
3,032
828,702
2009-05-06T08:56:00.000
5
0
0
0
python,django,postgresql,caching,memcached
829,260
5
true
1
0
At my previous work we tried to measure caching impact on site we was developing. On the same machine we load-tested the set of 10 pages that are most commonly used as start pages (object listings), plus some object detail pages taken randomly from the pool of ~200000. The difference was like 150 requests/second to 30000 requests/second and the database queries dropped to 1-2 per page. What was cached: sessions lists of objects retrieved for each individual page in object listing secondary objects and common content (found on each page) lists of object categories and other categorising properties object counters (calculated offline by cron job) individual objects In general, we used only low-level granular caching, not the high-level cache framework. It required very careful design (cache had to be properly invalidated upon each database state change, like adding or modifying any object).
3
5
0
I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db. I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I would like to know exactly what would be the benefits of such a change: I imagine that my site may be just not big enough for the better cache backend to make a difference. The point is: it wouldn't be me who would be installing and configuring memcached, and I don't want to waste somebody's time for nothing or very little. How can I measure the overhead introduced by using the db as the cache backend? I've looked at django-debug-toolbar, but if I understand correctly it isn't something you'd like to put on a production site (you have to set DEBUG=True for it to work). Unfortunately, I cannot quite reproduce the production setting on my laptop (I have a different OS, CPU and a lot more RAM). Has anyone benchmarked different Django cache/session backends? Does anybody know what would be the performance difference if I was doing, for example, one session-write on every request?
How to measure Django cache performance?
1.2
0
0
3,032
828,862
2009-05-06T09:44:00.000
1
0
1
0
python
830,235
6
false
0
0
I recently switched from python2.5 to 2.6 for my research project involving lots of 3rd party libs (scipy, pydot, etc.) and swig related stuff. The only thing I had to change was to convert all strings with s = unicode(s, "utf-8") before I fed them into the logging module. Otherwise, I got everytime Traceback (most recent call last): File "/usr/lib/python2.6/logging/__init__.py", line 773, in emit stream.write(fs % msg.encode("UTF-8")) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 31: ordinal not in range(128)
5
7
0
Or should I just stick with Python2.5 for a bit longer?
Is Python2.6 stable enough for production use?
0.033321
0
0
849
828,862
2009-05-06T09:44:00.000
1
0
1
0
python
829,464
6
false
0
0
I've found 2.6 to be fairly good with two exceptions: If you're using it on a server, I've had trouble in the past with some libraries which are used by elements of the server (Debian Etch IIRC). It's possible with a bit of jiggery pokery to maintain several versions of python in unison though if you're careful :-) This is no-longer true, but the last time I tried 2.6, wxPython had not been updated which meant all my gui tools I've written broke. There's now a version available that's built against 2.6. So I'd suggest you check all the modules you use and check their compatibility with 2.6...
5
7
0
Or should I just stick with Python2.5 for a bit longer?
Is Python2.6 stable enough for production use?
0.033321
0
0
849
828,862
2009-05-06T09:44:00.000
4
0
1
0
python
828,994
6
false
0
0
Yes it it, but this is not the right question. The right question is "can I use Python 2.6, taking in consideration the incompatibilities it introduces ?". And the short answser is "most probably yes, unless you use a specific lib that wouldn't work with 2.6, which is pretty rare".
5
7
0
Or should I just stick with Python2.5 for a bit longer?
Is Python2.6 stable enough for production use?
0.132549
0
0
849
828,862
2009-05-06T09:44:00.000
10
0
1
0
python
828,894
6
false
0
0
Ubuntu has switched to 2.6 in it's latest release, and has not had any significant problems. So I would say "yes, it's stable".
5
7
0
Or should I just stick with Python2.5 for a bit longer?
Is Python2.6 stable enough for production use?
1
0
0
849
828,862
2009-05-06T09:44:00.000
6
0
1
0
python
828,951
6
false
0
0
It depends from libraries you use. For example there is no precompiled InformixDB package for 2.6 if you have to use Python on Windows. Also web2py framework sticks with 2.5 because of some bug in 2.6. Personally I use CPython 2.6 (workhorse) and 3.0 (experimental), and Jython 2.5 beta (for my test with JDBC and ODBC).
5
7
0
Or should I just stick with Python2.5 for a bit longer?
Is Python2.6 stable enough for production use?
1
0
0
849
830,597
2009-05-06T16:51:00.000
0
0
0
1
python,google-app-engine,exception-handling,web-applications
833,840
2
false
1
0
Ad. #4: I usually treat query strings as non-essential. If anything is wrong with query string, I'd just present bare resource page (as if no query was present), possibly with some information to user what was wrong with the query string. This leads to the problem similar to your #3: how did the user got into this wrong query? Did my application produce wrong URL somewhere? Or was it outdated link in some external service, or saved bookmark? HTTP_REFERER might contain some clue, but of course is not authoritative, so I'd log the problematic query (with some additional HTTP headers) and try to investigate the case.
1
6
0
I'm developing a project on google app engine (webapp framework). I need you people to assess how I handle exceptions. There are 4 types of exceptions I am handling: Programming exceptions Bad user input Incorrect URLs Incorrect query strings Here is how I handle them: I have subclassed the webapp.requesthandler class and overrode the handle_exceptions method. Whenever an exception occurs, I take the user to a friendly "we're sorry" page and in the meantime send a message with the traceback to the admins. On the client side I (will) use js and also validate on the server side. Here I figure (as a coder with non-web experience) in addition to validate inputs according to programming logic (check: cash input is of the float type?) and business rules (check: user has enough points to take that action?), I also have to check against malicious intentions. What measures should I take against malicious actions? I have a catch-all URL that handles incorrect URLs. That is to say, I take the user to a custom "page does not exist" page. Here I have no problems, I think. Incorrect query strings presumably raise exceptions if left to themselves. If an ID does not exist, the method returns None (an exception is on the way). if the parameter is inconvenient, the code raises an exception. Here I think I must raise a 404 and take the user to the custom "page does not exist" page. What should I do? What are your opinions? Thanks in advance..
design for handling exceptions - google app engine
0
0
0
1,603
831,217
2009-05-06T19:11:00.000
1
0
1
0
python,com
7,378,250
2
false
0
0
Given the lack of popularity of COM I've ended up providing XMLRPC interface at least I know how to diagnose errors if they occur.
1
1
0
I'd like to create a COM server that can hold it state across the calls. My goal is to have a thread-safe in-memory database. And provide an access to it via COM interface. Is that possible?
How to make a persistent com server in Python
0.099668
0
0
247
832,485
2009-05-07T01:12:00.000
1
0
1
0
python
832,590
6
false
0
0
The short answer is just guess at what a good hash parameter would be that matches your ideas of "similar". Probably just something like sum of all the letters (A) and the sum of the differences between adjacent letters (B), might work. For each new string, use its A and B values to quickly lookup a now much smaller set of similar strings, and then do a more careful comparison between these. This probably isn't the purest solution, but practically, lots of problems are solved this way. Beyond this, I think there is currently quite a bit of work solving similar problems in genetics (i.e. finding similar gene sequences within huge databases), but I don't think there's an accepted generic solution to this problem.
1
3
0
I have sets of strings in a database. Each set will have less than 500 members, there will be tens of thousands of sets, and the strings are natural language. I would like to detect duplicate strings within each set. New strings will be compared with an existing set, and added to the database if they are unique. Are there hashing algorithms that would be effective at finding (very) similar strings? For example, the strings probably would have the same number of words, but the encoding may be slightly different (UTF-8 vs Latin-1).
Duplicate text detection / hashing
0.033321
0
0
3,199