Q_Id
int64 337
49.3M
| CreationDate
stringlengths 23
23
| Users Score
int64 -42
1.15k
| Other
int64 0
1
| Python Basics and Environment
int64 0
1
| System Administration and DevOps
int64 0
1
| Tags
stringlengths 6
105
| A_Id
int64 518
72.5M
| AnswerCount
int64 1
64
| is_accepted
bool 2
classes | Web Development
int64 0
1
| GUI and Desktop Applications
int64 0
1
| Answer
stringlengths 6
11.6k
| Available Count
int64 1
31
| Q_Score
int64 0
6.79k
| Data Science and Machine Learning
int64 0
1
| Question
stringlengths 15
29k
| Title
stringlengths 11
150
| Score
float64 -1
1.2
| Database and SQL
int64 0
1
| Networking and APIs
int64 0
1
| ViewCount
int64 8
6.81M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,818,969 | 2009-11-30T10:20:00.000 | 3 | 0 | 0 | 0 | python,selenium | 1,819,059 | 2 | false | 0 | 0 | You should be able to use the stop and start commands. You will need to ensure that you are not clearing cookies between sessions, and depending on the browser you're launching you may also need to use the -browserSessionReuse command line option. | 2 | 1 | 0 | I'm writing a script which needs the browser that selenium is operating close and re-open, without losing its cookies.
Any idea on how to go about it?
Basically, it's a check to see that if the user opens and closes his browser, his cookies stay intact. | Close and open a new browser in Selenium | 0.291313 | 0 | 1 | 1,370 |
1,818,969 | 2009-11-30T10:20:00.000 | 0 | 0 | 0 | 0 | python,selenium | 1,819,042 | 2 | false | 0 | 0 | This is a feature of the browser and not your concern: If there is a bug in the browser, then there is little you can do. If you need to know whether a certain version of the browser works correctly, then define a manual test (write a document that explains the steps), do it once and record the result somewhere (like "Browser XXX version YYY works").
When you know that a certain browser (version) works, then that's not going to change, so there is no need to repeat the test. | 2 | 1 | 0 | I'm writing a script which needs the browser that selenium is operating close and re-open, without losing its cookies.
Any idea on how to go about it?
Basically, it's a check to see that if the user opens and closes his browser, his cookies stay intact. | Close and open a new browser in Selenium | 0 | 0 | 1 | 1,370 |
1,819,903 | 2009-11-30T13:42:00.000 | 1 | 0 | 0 | 0 | javascript,python,testing,selenium,selenium-rc | 1,902,514 | 2 | false | 1 | 0 | If you are purely testing that the JavaScript functions are performing the correct calculations with the given inputs, I would suggest separating your JavaScript from your page and use a JavaScript testing framework to test the functionality. Testing low level code using Selenium is a lot of unnecessary overhead. If you're going against the fully rendered page, this would require your application to be running to a server, which should not be a dependency of testing raw JavaScript.
We recently converted our application from using jsUnit to use YUI Test and it has been promising so far. We run about 150 tests in both FireFox and IE in less than three minutes. Our testing still isn't ideal - we still test a lot of JavaScript the hard way using Selenium. However, moving some of the UI tests to YUI Test has saved us a lot of time in our Continuous Integration environment. | 1 | 3 | 0 | My Application has a lot of calculation being done in JavaScript according to how and when the user acts on the application. The project prints out valuable information (through console calls) as to how this calculation is going on, and so we can easily spot any NaNs creeping in.
We are planning to integrate Selenium (RC with python) to test or project, but if we could get the console output messages in the python test case, we can identify any NaNs or even any miscalculations.
So, is there a way that Selenium can absorb these outputs (preferably in a console-less environment)?
If not, I would like to know if I can divert the console calls, may be by rebinding the console variable to something else, so that selenium can get that output and notify the python side. Or if not console, is there any other way that I can achieve this.
I know selenium has commands like waitForElementPresent etc., but I don't want to show these intermediate calculations on the application, or is it the only way?
Any help appreciated.
Thank you. | Javascript communication with Selenium (RC) | 0.099668 | 0 | 1 | 2,109 |
1,820,657 | 2009-11-30T15:55:00.000 | 1 | 0 | 1 | 0 | python | 1,820,679 | 7 | false | 0 | 0 | The standard library, especially the built-in functions. They seem trivial but can yield impressive results!
It really pays to know the basics of a default python installation. If you doubt that just follow the Stack Overflow python questions. Some answers are just amazing :) | 1 | 3 | 0 | Though there can be many but as i am very new to python so which modules or classes within standard libraries i should know when programming in python, especially when i am practicing programming challenges from a C++ book? Libraries which can make my life easier? Since there can be no single correct answer, i am making this question a wiki. | Must Standard libraries for python beginner | 0.028564 | 0 | 0 | 2,252 |
1,822,541 | 2009-11-30T21:32:00.000 | 10 | 0 | 1 | 0 | python,multithreading | 1,977,542 | 2 | true | 0 | 0 | Two points:
In officially released Python versions (2.4, 2.5... up to 3.1), an RLock is much slower than a Lock, because Locks are implemented in C and RLocks in Python (this will change in 3.2)
A Lock can be released from any thread (not necessarily the thread which acquire()d it), while an RLock has to be released by the same thread which acquired it
Bottom line, I'd suggest to only use an RLock if it matches the semantics you are looking for, otherwise stick to Locks by default. | 2 | 15 | 0 | the threading module in Python provides two kinds of locks: A common lock and a reentrant lock. It seems to me, that if I need a lock, I should always prefer the RLock over the Lock; mainly to prevent deadlock situations.
Besides that, I see two points, when to prefer a Lock over a RLock:
RLock has a more complicated internal structure and may therefore have worse performance.
Due to some reason, I want to prevent a thread recursing through the lock.
Is my reasoning correct? Can you point out other aspects? | Is RLock a sensible default over Lock? | 1.2 | 0 | 0 | 4,111 |
1,822,541 | 2009-11-30T21:32:00.000 | 3 | 0 | 1 | 0 | python,multithreading | 1,822,925 | 2 | false | 0 | 0 | Normally you should structure your code such that you never need to recursively lock in normal operation (basically it forces you to use locks tightly around the protected datastructures they are are protecting). Therefore you want to catch an anomalous recursive locking. | 2 | 15 | 0 | the threading module in Python provides two kinds of locks: A common lock and a reentrant lock. It seems to me, that if I need a lock, I should always prefer the RLock over the Lock; mainly to prevent deadlock situations.
Besides that, I see two points, when to prefer a Lock over a RLock:
RLock has a more complicated internal structure and may therefore have worse performance.
Due to some reason, I want to prevent a thread recursing through the lock.
Is my reasoning correct? Can you point out other aspects? | Is RLock a sensible default over Lock? | 0.291313 | 0 | 0 | 4,111 |
1,823,372 | 2009-12-01T00:46:00.000 | 0 | 0 | 0 | 0 | python,django,django-models | 1,823,488 | 2 | false | 1 | 0 | There are a variety of ways to do this. I suggest the following:
Django has a messaging framework, built by design to show messages to users only once when the software creates them. Whenever X is created/modified/deleted etc, you can add the message to the user via User.message_set.create(message='Whatever you like'). This will be shown to the user once. This relies on django sessions, which I assume you're using since you're relying on the built-in user model. These messages are stored in auth_message.
HTH | 1 | 0 | 0 | I have a simple webapp in Django for an iPhone app.
I want to prompt the user to review our product, but just once. I then don't want to show that prompt again.
So would the best practise way of implementing this to be to add a new entry to the user profile model with a bolean field: "reviewed" - and then set that flag when the user completes the action?
I would then check for that entry in my template and display or not, the prompt.
I've not yet worked with database models, extended the user model, or saved to custom DB fields, so any thoughts or examples on this would be most welcome. I'm a little nervous as my site has live users and I won't want to break the user tables. | Set and use flags against a users profile model in Django | 0 | 0 | 0 | 1,168 |
1,823,431 | 2009-12-01T01:08:00.000 | 2 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,545 | 13 | false | 0 | 0 | I also vote for python. When do algorithm, we tend to work on the algorithm itself rather than language, low level details. Basically, we works on abstraction level. And using python, we're less likely to be side-tracked.
But if you're very familiar and comfortable with C++ and can use it freely to express your idea, just use it. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0.03076 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 1 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,577 | 13 | false | 0 | 0 | If using C++ means that STL is fair game, I'd say that it deserves serious consideration. STL is a fantastic library, combining structures, iterators, and algorithms. I love the Python recommendations, but if I could use STL I'd reconsider C++. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0.015383 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 2 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,589 | 13 | false | 0 | 0 | With C++, you'd sometimes be concentrating more on the language issues than the problem itself, so Python. I'd even be recommending you do it in a higher-level language like Matlab (although the language itself can be a bit ugly). | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0.03076 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 0 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,580 | 13 | false | 0 | 0 | Remember that Python is compiled to bytecode and then interpreted in a VM. So, in performance isn't better (faster) than C++. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 3 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,479 | 13 | false | 0 | 0 | Algorithms are fine in Python (allthough you can only fly one OS scheduled python thread due to the global lock); however, when it comes to data structures + algorithms you need fixed complexity guarantees, and this case you mix Python with C.
I suppose what I have said applies more to long running computations. You can emulate data structures on-top of the python hashmap primitive. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0.046121 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 4 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,473 | 13 | false | 0 | 0 | I would go for python. And if you really need the performance, then you can always write C/C++ extensions and use them in python. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0.061461 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 8 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,434 | 13 | false | 0 | 0 | A bit subjective, but I'd vote for python because it has good libraries and abstracts a lot of the low level 'detail' that you'd have to consider when using c++... | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 1 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 6 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,440 | 13 | false | 0 | 0 | I did all my algorithms work in college in C++ because I knew it.
If I'd had to learn a language at the same time, I would have picked Python most likely. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 1 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 6 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,447 | 13 | false | 0 | 0 | I am under the impression that it really depends from what you mean by faster.
Faster to develop: go python.
Faster to run: go C++.
However python can use a lot of external C libraries, so the difference in processing time might not be that relevant, depending on the type of implementation. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 1 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 5 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,457 | 13 | false | 0 | 0 | At my university the 500 students in the "Algorithms and Datastructures" class get to choose the language they want.
Python is by far the most popular choice there, and personally I'm happy I also chose that, even though I already knew C++. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 0.076772 | 0 | 0 | 1,482 |
1,823,431 | 2009-12-01T01:08:00.000 | 23 | 1 | 1 | 0 | c++,python,algorithm,graph | 1,823,475 | 13 | true | 0 | 0 | I think you're looking for Python, because you can:
Focus on the algorithms themselves and not have to worry about other detail like memory management.
Do more with less code
The syntax is almost like working with pseudo code.
There is great built in language support for lists, tuples, list comprehensions, etc...
But more specifically...
If by better you mean speed of development, then chose Python.
If by better you mean sheer execution speed, then chose C++. | 11 | 4 | 0 | I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise.
EDIT 2: I plan to use python-graph lib from Google-codes, Please provide example codes if you have used it.
EDIT 1: faster - less time && less work to code the solution
Thank you all for your help ! | which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs)? | 1.2 | 0 | 0 | 1,482 |
1,825,692 | 2009-12-01T11:51:00.000 | 1 | 0 | 0 | 0 | python,macos,clipboard | 6,888,324 | 7 | false | 0 | 0 | if you just wanted to put text into the mac clipboard, you could use the shell's pbcopy command. | 1 | 41 | 0 | I'd like my python program to place some text in the Mac clipboard.
Is this possible? | Can python send text to the Mac clipboard | 0.028564 | 0 | 0 | 23,252 |
1,828,040 | 2009-12-01T18:38:00.000 | 1 | 0 | 1 | 0 | python,visual-studio,google-app-engine | 1,828,477 | 4 | true | 0 | 0 | Thanks for all the responses. I did scan through some Python IDEs (and their screenshots) and decided to check out IronPythonStudio. My .py files now get colour coded nicely, and there's some intellisense :) Unfortunately Ctrl+K,D doesn't work, but it's much nicer to code than the plain yellow text I had earlier.
For anyone that's a massive Visual Studio fanboy like me, IronPythonStudio is definitely better than just coding it as text ;o) | 1 | 2 | 0 | I've started messing around with Google App Engine, writing Python.
I love Visual Studio for many reasons, but currently my .py files just look like text.
I've searched the web looking for a way to get it to highlight python files (intellisense would be a nice bonus, but not required) but turned up nothing.
There are other questions on SO about this, but all the answers point at different IDEs, or installing IronPythonStudio (which seems overkill since I only want to colouring, and it might behave differently being geared at .NET anyway).
Does anyone know how to simple get VS to highlight Python? Is it really that uncommon? :( | Python syntax highlighting / Intellisense? | 1.2 | 0 | 0 | 2,992 |
1,828,345 | 2009-12-01T19:32:00.000 | 4 | 0 | 0 | 0 | python,image-processing,python-imaging-library,rounded-corners | 1,839,511 | 4 | true | 0 | 0 | So, okay, i found the solution.
I used the supersampling method bobince proposed before, but i found that the images become blurry. So, I would not provide the full code, but i'll explain my solution.
It may seem kind of idiotistic, but i haven't found any other way to do it without involving any other libraries.
With PIL you draw white (or whatever color you need, involving transparent ones) corners on the image. Then you copy it. You should now have two images with crispy non-antialiased white round corners.
Now you should use scale-up -> scale-down supersampling (see bobince's answer above for details) method to make one of the images smooth (i used 8x scaling).
Now you have two images - one with crispy corners and another one with smooth corners, but with blurry picture.
You have now to make corners on crispy image transparent and paste the whole image on the smooth one. I used the Image.composite(crispy_image, smooth_image, crispy_image) method in PIL library to do this.
Voila! | 1 | 15 | 0 | Is there any way to make nice round corners with python? Currently PIL and GD2 are used in my project. Both of them have an arc() method, that allows you to draw a quater-circle, but the quater-circle is not antialiased, so the image looks crispy.
Is there any neat way to make antialiased/smooth round corners? | Any way to make nice antialiased round corners for images in python? | 1.2 | 0 | 0 | 11,006 |
1,828,567 | 2009-12-01T20:10:00.000 | 3 | 0 | 1 | 0 | python,qt,qt4,pyqt,pyqt4 | 1,828,607 | 1 | true | 0 | 1 | If the underlaying C++ methods are virtual, your Python methods that override them will be called any time C++ code calls them. If they are just regular methods, any C++ code will call the original C++ methods by default (Python code will call the Python methods though, because it sees the Python object and all methods are "virtual" there). | 1 | 4 | 0 | The usual way to use Qt widgets from Python seems to be to subclass them.
Qt widget classes have a great many methods, so inevitably I'm going to end up adding a method to the subclass, with the same name as one inherited from the Qt widget. In Python, all methods are virtual, so what I'm concerned about is that some Qt code might end up calling my method instead of the expected Qt one - in the worst-case scenario, breaking some edge case that doesn't easily show up in testing.
On the other hand, maybe all the PyQt methods are just wrappers for C++ code, which would of course be unaffected by anything I do in terms of Python subclassing.
Anyone know offhand which is the case? | PyQt subclassing | 1.2 | 0 | 0 | 1,972 |
1,829,256 | 2009-12-01T22:02:00.000 | 0 | 0 | 0 | 0 | python,sqlite,compression | 1,829,601 | 3 | false | 0 | 0 | what sort of parsing do you do before you put it in the database? I get the impression that it is fairly simple with a single table holding each entry - if not then my apologies.
Compression is all about removing duplication, and in a log file most of the duplication is between entries rather than within each entry so compressing each entry individually is not going to be a huge win.
This is off the top of my head so feel free to shoot it down in flames, but I would consider breaking the table into a set of smaller tables holding the individual parts of the entry. A log entry would then mostly consist of a timestamp (as DATE type rather than a string) plus a set of indexes into other tables (e.g. requesting IP, request type, requested URL, browser type etc.)
This would have a trade-off of course, since it would make the database a lot more complex to maintain, but on the other hand it would enable meaningful queries such as "show me all the unique IPs that requested page X in the last week". | 2 | 0 | 0 | I recently created a script that parses several web proxy logs into a tidy sqlite3 db file that is working great for me... with one snag. the file size. I have been pressed to use this format (a sqlite3 db) and python handles it natively like a champ, so my question is this... what is the best form of string compression that I can use for db entries when file size is the sole concern. zlib? base-n? Klingon?
Any advice would help me loads, again just string compression for characters that are compliant for URLs. | Python 3: Best string compression method to minimize the size of a sqlite3 db | 0 | 1 | 0 | 2,957 |
1,829,256 | 2009-12-01T22:02:00.000 | 0 | 0 | 0 | 0 | python,sqlite,compression | 1,832,688 | 3 | false | 0 | 0 | Instead of inserting compression/decompression code into your program, you could store the table itself on a compressed drive. | 2 | 0 | 0 | I recently created a script that parses several web proxy logs into a tidy sqlite3 db file that is working great for me... with one snag. the file size. I have been pressed to use this format (a sqlite3 db) and python handles it natively like a champ, so my question is this... what is the best form of string compression that I can use for db entries when file size is the sole concern. zlib? base-n? Klingon?
Any advice would help me loads, again just string compression for characters that are compliant for URLs. | Python 3: Best string compression method to minimize the size of a sqlite3 db | 0 | 1 | 0 | 2,957 |
1,829,872 | 2009-12-02T00:15:00.000 | 1 | 0 | 1 | 0 | python,datetime,sqlite | 48,429,766 | 3 | false | 0 | 0 | Note: In Python3, I had to change the SQL to something like:
SELECT jobid, startedTime as "st [timestamp]" FROM job
(I had to explicitly name the column.) | 1 | 84 | 0 | I'm using the sqlite3 module in Python 2.6.4 to store a datetime in a SQLite database. Inserting it is very easy, because sqlite automatically converts the date to a string. The problem is, when reading it it comes back as a string, but I need to reconstruct the original datetime object. How do I do this? | How to read datetime back from sqlite as a datetime instead of string in Python? | 0.066568 | 1 | 0 | 58,748 |
1,830,042 | 2009-12-02T01:03:00.000 | 0 | 0 | 0 | 0 | python,mako | 1,830,276 | 1 | true | 1 | 0 | You have two OO design choices for your page controllers.
Common features can be handled two ways.
Inheritance. All page controllers are subclasses of a common class that provides the common attributes.
Delegation. All page controllers are part of a pipeline where some common process (either before or after the page controller) folds in the additional information.
You have to pick one. | 1 | 1 | 0 | I'm using Mako's inheritance features to factor out common page elements, like a header and footer, into a "base.mako" template. Page-specific controllers use their own templates, which inherit base.mako.
base.mako needs a set of variables -- for example, the name of the logged-on user goes in the header for all pages. However, it's the individual page controller that selects and renders the template, and is therefore responsible for passing variables to it.
I'd rather all of those page controllers not have to know what the base template needs in its context. What's a good way to establish the context for the base template in a situation like this?
Thanks in advance! | Good way to pass variables for common elements to Mako templates? | 1.2 | 0 | 0 | 1,022 |
1,830,370 | 2009-12-02T02:49:00.000 | 0 | 0 | 0 | 1 | python,process,kill | 1,853,165 | 3 | false | 0 | 0 | Zombie processes are actually just an entry in the process table. They do not run, they don't consume memory; the entry just stays because the parent hasn't checked their exit code.
You can either do a double fork as Gonzalo suggests, or you can filter out all ps lines with a Z in the S column. | 2 | 1 | 0 | In my Python script, I first launch a subprocess by subprocess.Popen(). Then later on, I want to kill that subprocess by kill -9 Pid.
What I found is that after the kill is executed, the subprocess is "stopped" because the GUI window of that process disappeared immediately. But when I perform a "ps aux" right after the kill, the same process (with same pid) is still shown in the result. The difference is the command of the process is included in a pair of () like below:
root 30506 0.0 0.0 0 0 s000 Z+ 6:13PM
0:00.00 (sample process)
This breaks my process detect logical since the dead process still can be found by ps.
Anyone know why this is happening?
Thanks! | why Ghost Process appears after kill -9 | 0 | 0 | 0 | 845 |
1,830,370 | 2009-12-02T02:49:00.000 | 0 | 0 | 0 | 1 | python,process,kill | 1,830,395 | 3 | false | 0 | 0 | I think -9 signal lets the process to try to handle kill and spend some time housekeeping. You can try just kill the process without signal.
Edit: oh, its actually -15 signal, that lets process die gracefully. never mind. | 2 | 1 | 0 | In my Python script, I first launch a subprocess by subprocess.Popen(). Then later on, I want to kill that subprocess by kill -9 Pid.
What I found is that after the kill is executed, the subprocess is "stopped" because the GUI window of that process disappeared immediately. But when I perform a "ps aux" right after the kill, the same process (with same pid) is still shown in the result. The difference is the command of the process is included in a pair of () like below:
root 30506 0.0 0.0 0 0 s000 Z+ 6:13PM
0:00.00 (sample process)
This breaks my process detect logical since the dead process still can be found by ps.
Anyone know why this is happening?
Thanks! | why Ghost Process appears after kill -9 | 0 | 0 | 0 | 845 |
1,831,212 | 2009-12-02T07:33:00.000 | 0 | 1 | 0 | 0 | c++,python,bignum,gmp,arbitrary-precision | 1,831,277 | 3 | false | 0 | 0 | Did you do profiling ? Of Python and C++ whole applications. So that you know that you really need that additional speed.
Try Python 3k it now have any-length integers implemented! | 1 | 5 | 0 | I have been using python's native bignums for an algorithm and decided to try and speed it up by converting it to C++. When I used long longs, the C++ was about 100x faster than the python, but when I used GMP bindings in C++, it was only 10x faster than the python (for the same cases that fit in long longs).
Is there a better bignum implementation for doing a large number of small additions? For example, we have a big number N we'll be adding a lot of little +1, +21, +1, etc. and every once and a while adds another big number M? | Bignum implementation that has efficient addition of small integers | 0 | 0 | 0 | 1,568 |
1,831,979 | 2009-12-02T10:21:00.000 | 2 | 0 | 0 | 0 | python,compilation,mysql | 1,832,065 | 2 | false | 0 | 0 | If you've only built one architecture (i386 / PPC) then it won't work on Macs with the opposite architecture. Are the machines that don't work PPC machines, by any chance?
Sometimes build configurations are set up to build only the current architecture by default - I haven't build Python-MySQLDB so I'm not sure if this is the case here, but it's worth checking.
You can find out which architectures have been built with the 'file' command in Terminal.
(Incidentally do you mean ".so"? I'm not familiar with ".co" files.) | 1 | 0 | 0 | I want to use Python-MySQLDB library on Mac so I have compiled the source code to get the _mysql.so under Mac10.5 with my Intel iMac (i386)
This _mysql.co works in 2 of my iMacs and another Macbook. But that's it, it doesn't work in any other Macs.
Does this mean some machine specific info got compiled into the file? | Why _mysql.co that compiled on one Mac doesn't work on another? | 0.197375 | 1 | 0 | 106 |
1,832,767 | 2009-12-02T13:02:00.000 | 1 | 0 | 1 | 0 | asp.net,visual-studio,visual-studio-2008,ironpython | 1,836,945 | 1 | true | 0 | 0 | You'll need to dig into the object's dictionary. This should be the dict field on the object. If the variable is in the class instead you'll need to dig into the class and then into the classes dictionary. Unfortunately it's rather painful to do right now.
This is already improved for a future release of IronPython - checked into the current source tree (which will likely become 2.6.1) there's support via debugger proxies which make this much better. So if you're using 2.6 and are willing to build from source you could grab the current sources and give that a go. | 1 | 1 | 0 | I need to inspect the value of a variable inside a class in asp.net IronPython in Visual Studio 2008. Visual Studio 2008 inspector doesnt work for IronPython (if the inspector works in VS 2008 for asp.net IronPython and it isnt working for me plz tell me) and you can't use Response.write - Response.end inside a class. What can I do to know the variable's value? | Variable inspection in Visual Studio 2008 in asp.net IronPython inside a class | 1.2 | 0 | 0 | 237 |
1,832,893 | 2009-12-02T13:25:00.000 | 4 | 0 | 1 | 0 | python,regex,unicode,ucd,character-properties | 1,852,463 | 6 | false | 0 | 0 | Note that while \p{Ll} has no equivalent in Python regular expressions, \p{Zs} should be covered by '(?u)\s'.
The (?u), as the docs say, “Make \w, \W, \b, \B, \d, \D, \s and \S dependent on the Unicode character properties database.” and \s means any spacing character. | 2 | 71 | 0 | Perl and some other current regex engines support Unicode properties, such as the category, in a regex. E.g. in Perl you can use \p{Ll} to match an arbitrary lower-case letter, or p{Zs} for any space separator. I don't see support for this in either the 2.x nor 3.x lines of Python (with due regrets). Is anybody aware of a good strategy to get a similar effect? Homegrown solutions are welcome. | Python regex matching Unicode properties | 0.132549 | 0 | 0 | 17,447 |
1,832,893 | 2009-12-02T13:25:00.000 | 4 | 0 | 1 | 0 | python,regex,unicode,ucd,character-properties | 1,833,228 | 6 | false | 0 | 0 | You're right that Unicode property classes are not supported by the Python regex parser.
If you wanted to do a nice hack, that would be generally useful, you could create a preprocessor that scans a string for such class tokens (\p{M} or whatever) and replaces them with the corresponding character sets, so that, for example, \p{M} would become [\u0300–\u036F\u1DC0–\u1DFF\u20D0–\u20FF\uFE20–\uFE2F], and \P{M} would become [^\u0300–\u036F\u1DC0–\u1DFF\u20D0–\u20FF\uFE20–\uFE2F].
People would thank you. :) | 2 | 71 | 0 | Perl and some other current regex engines support Unicode properties, such as the category, in a regex. E.g. in Perl you can use \p{Ll} to match an arbitrary lower-case letter, or p{Zs} for any space separator. I don't see support for this in either the 2.x nor 3.x lines of Python (with due regrets). Is anybody aware of a good strategy to get a similar effect? Homegrown solutions are welcome. | Python regex matching Unicode properties | 0.132549 | 0 | 0 | 17,447 |
1,834,829 | 2009-12-02T18:22:00.000 | 1 | 1 | 0 | 0 | python,ruby-on-rails,pylons | 1,864,605 | 5 | false | 1 | 0 | Clarity and ease of use are some of Pythons biggest selling points. In saying that, the different Python web frameworks cover almost the entire spectrum from small and simple all the way up to large and complex with everything in between.
You should find that most Python web frameworks have less 'magic' than Rails - ie they are a bit more explicit which is arguably better from the clarity point of view.
In my opinion, even if you enjoy Rails and don't ever plan on leaving, you should still try out other languages and frameworks occasionally to give you a broader perspective.
Personally I like Turbogears2, but I think Django would make a good starting point for a Rails developer that wanted to try out something else. | 1 | 2 | 0 | I have been working with Ruby on Rails for over a year now and have been offered some development work with Python. I would like know if development with Python is as enjoyable as Ruby in terms of the clarity and ease of use. And how well is Python suited for Web development. I've heard of Pylons being a direct port of the Rails framework but does it provide the same level of comfort and features. Are there any popular websites built using Python and a framework that offers the same level of flexibilty as Rails.
Because Rails doesn't seem like work. | Python after Ruby on Rails | 0.039979 | 0 | 0 | 1,541 |
1,834,850 | 2009-12-02T18:26:00.000 | 46 | 1 | 1 | 1 | python,powershell,scripting | 1,835,086 | 8 | false | 0 | 0 | Python works as a great, all-purpose tool if you're looking to replace CMD and BAT scripts on your Windows boxes, and can also be written to run scripts on your (L)inux boxes, too. It's a great, flexible language and can handle many tasks you throw at it.
That being said, PowerShell is an amazingly versatile tool for administering all manner of Windows boxes; it has all the power of .NET, with many more interfaces into MS products such as Exchange and Active Directory, which are a timesaver. Depending on your situation, you may get more use of of PS than other scripting languages just because of the interfaces available to MS products, and I know MS seems to have made a commitment to providing those APIs in a lot of products. PowerShell comes installed on all current versions of Windows (Windows 7+, Windows Server 2008+), and is fairly easily installed on older versions.
To address your edit that your scripts will be used to launch other processes, I think in that case either of the tools fit the bill. I would recommend PS if you plan on adding any admin-ish tasks to the scripts rather than just service calls, but if you stick to what you described, Python is good. | 6 | 32 | 0 | What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.
The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.
We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future. | Python, PowerShell, or Other? | 1 | 0 | 0 | 44,901 |
1,834,850 | 2009-12-02T18:26:00.000 | 3 | 1 | 1 | 1 | python,powershell,scripting | 1,836,471 | 8 | false | 0 | 0 | If all you do is spawning a lot of system specific programs with no or little programming logic behind then OS specific shell might be a better choice than a full general purpose programming language. | 6 | 32 | 0 | What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.
The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.
We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future. | Python, PowerShell, or Other? | 0.07486 | 0 | 0 | 44,901 |
1,834,850 | 2009-12-02T18:26:00.000 | 2 | 1 | 1 | 1 | python,powershell,scripting | 1,835,112 | 8 | false | 0 | 0 | I find it sad no one yet mentioend good ol' Perl. | 6 | 32 | 0 | What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.
The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.
We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future. | Python, PowerShell, or Other? | 0.049958 | 0 | 0 | 44,901 |
1,834,850 | 2009-12-02T18:26:00.000 | 2 | 1 | 1 | 1 | python,powershell,scripting | 1,834,895 | 8 | false | 0 | 0 | The questions is kind of vague, but Python is much more portable than PowerShell; however, Python isn't that prevalent on Windows. But on the other hand, I don't believe PowerShell scripts will work on a Windows machine that doesn't have PowerShell. Meaning they may not work in the old fashioned cmd shell. I think you'll find more documentation and libraries for Python as well.
PowerShell is more like Bash than it is a programming language like Python.
Maybe you could explain what you want to do with your scripts and you'll probably get better answers. | 6 | 32 | 0 | What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.
The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.
We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future. | Python, PowerShell, or Other? | 0.049958 | 0 | 0 | 44,901 |
1,834,850 | 2009-12-02T18:26:00.000 | 20 | 1 | 1 | 1 | python,powershell,scripting | 1,836,342 | 8 | false | 0 | 0 | We would like to standardize our scripting and are currently using bat and cmd files as the standard.
It sounds like Windows is your predominate environment.
If so, PowerShell would be much better than Python.
PowerShell is included with Windows
Server 2008. No need to
deploy/install Python runtime on
every new server that rolls in.
The entire Microsoft server related software (Exchange, Systems Center, etc) is transitioning to PowerShell cmdlets for functionality and extensions
3rd party vendors (e.g. SCOM plugins) will also use PowerShell scripts/cmdlets to expose functionality
I have more experience with Python than PowerShell but the writing is on the wall as far as the Microsoft ecosystem is concerned: go with PowerShell. Otherwise, you'll just be going against the grain and constantly interop-ing between Python and everyone else's cmdlets.
Just because you can code import win32com.client in Python does not put it on equal footing with PowerShell in the Windows environment. | 6 | 32 | 0 | What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.
The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.
We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future. | Python, PowerShell, or Other? | 1 | 0 | 0 | 44,901 |
1,834,850 | 2009-12-02T18:26:00.000 | 2 | 1 | 1 | 1 | python,powershell,scripting | 1,834,979 | 8 | false | 0 | 0 | One advantage to Python is the availability of third-party libraries and an extensive built-in standard library. You can do a lot of powerful operations quickly and easily with Python on a variety of operating systems and environments. That's one reason we use Python here at the office not only as a scripting language but for all of our database backend applications as well.
We also use it for XML and HTML scraping, using ElementTree and BeautifulSoup, which are very powerful and flexible Python-specific libraries for this sort of work. | 6 | 32 | 0 | What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.
The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.
We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future. | Python, PowerShell, or Other? | 0.049958 | 0 | 0 | 44,901 |
1,835,668 | 2009-12-02T20:43:00.000 | 1 | 0 | 0 | 0 | python,http | 1,837,070 | 3 | false | 1 | 0 | also:
web.py (webpy.org)
paste (pythonpaste.org) | 1 | 2 | 0 | There is CherryPy. Are there any others? | What Python-only HTTP/1.1 web servers are available? | 0.066568 | 0 | 1 | 507 |
1,835,930 | 2009-12-02T21:27:00.000 | 8 | 0 | 1 | 1 | python,zip | 1,835,980 | 2 | true | 0 | 0 | How would it overtake 2.5? You can install both in parallel, just make sure that you unselect the option to "Register Extensions" during the install of 2.6.
I have several Python installations on my PC in parallel, one of them my "standard" one that I expect to run when I doubleclick on a .py file, and the other one to invoke manually if I need it.
I have found, though, that sometimes file associations are lost completely after installing a new version without the "Register Extensions" option set. In that case just run a "repair installation" with your preferred standard version, and you should be good to go. | 2 | 1 | 0 | Not the source codes, thats the only thing i seem to find. I can't install py2.6 because it would overtake 2.5 and cause mayor mess in my pc. | Need a zip of Python 2.6 for windows | 1.2 | 0 | 0 | 1,012 |
1,835,930 | 2009-12-02T21:27:00.000 | 2 | 0 | 1 | 1 | python,zip | 1,836,803 | 2 | false | 0 | 0 | I have Pythons 2.3, 2.4, 2.5, 2.6, and 3.1 all installed on my PC. Download the .msi from python.org, and install it. | 2 | 1 | 0 | Not the source codes, thats the only thing i seem to find. I can't install py2.6 because it would overtake 2.5 and cause mayor mess in my pc. | Need a zip of Python 2.6 for windows | 0.197375 | 0 | 0 | 1,012 |
1,836,061 | 2009-12-02T21:49:00.000 | 2 | 0 | 0 | 0 | python,database | 1,836,125 | 2 | false | 0 | 0 | Well...DBAPI is that frontend:
This API has been defined to encourage similarity between the
Python modules that are used to access databases. By doing this,
we hope to achieve a consistency leading to more easily understood
modules, code that is generally more portable across databases,
and a broader reach of database connectivity from Python.
It has always worked great for me atleast, care to elaborate the problems you are facing? | 1 | 1 | 0 | Does there exist, or is there an intention to create, a universal database frontend for Python like Perl's DBI? I am aware of Python's DB-API, but all the separate packages are leaving me somewhat aggravated. | Python universal database interface? | 0.197375 | 1 | 0 | 1,158 |
1,836,884 | 2009-12-03T00:29:00.000 | -1 | 1 | 0 | 0 | python,mediawiki,wikitext | 2,321,542 | 3 | false | 0 | 1 | pywikipedia i have found to be best | 1 | 1 | 0 | I need to render wikitext (pulled from the database of a mediawiki of it's relevant) and display in some other format (ultimately to be rendered as a PDF, but basically any other format will do).
I can definately hack together something that does the job but ultimately I'll be writing it as I go along, and I can see that the overhead of implementing new tags as people in my team use them will eat up a lot of my time.
Is there a project to do this?
I saw TiddlyWiki which is written in python, which I will look into borrowing their library, but in the meantime I figured there may be a project that's a bit more niche that someone knows?
Cheers | Render wikitext with Python | -0.066568 | 0 | 0 | 2,209 |
1,836,987 | 2009-12-03T00:59:00.000 | 6 | 0 | 0 | 0 | python,google-app-engine,pycurl | 1,837,397 | 5 | false | 1 | 0 | Twill and mechanize don't do Javascript, and Qt and Selenium can't run on App Engine ((1)), which only supports pure Python code. I do not know of any pure-Python Javascript interpreter, which is what you'd need to deploy a JS-supporting scraper on App Engine:-(.
Maybe there's something in Java, which would at least allow you to deploy on (the Java version of) App Engine? App Engine app versions in Java and Python can use the same datastore, so you could keep some part of your app in Python... just not the part that needs to understand Javascript. Unfortunately I don't know enough about the Java / AE environment to suggest any specific package to try.
((1)): to clarify, since there seems to be a misunderstanding that has gotten so far as to get me downvoted: if you run Selenium or other scrapers on a different computer, you can of course target a site deployed in App Engine (it doesn't matter how the website you're targeting is deployed, what programming language[s] it uses, etc, etc, as long as it's a website you can access [[real website: flash, &c, may likely be different]]). How I read the question is, the OP is looking for ways to have the scraping run as part of an App Engine app -- that is the problematic part, not where you (or somebody else;-) runs the site being scraped! | 1 | 4 | 0 | I want to automate interaction with a webpage. I've been using pycurl up til now but eventually the webpage will use javascript so I'm looking for alternatives . A typical interaction is "open the page, search for some text, click on a link (which opens a form), fill out the form and submit".
We're deploying on Google App engine, if that makes a difference.
Clarification: we're deploying the webpage on appengine. But the interaction is run on a separate machine. So selenium seems like it's the best choice. | Automate interaction with a webpage in python | 1 | 0 | 1 | 9,387 |
1,837,686 | 2009-12-03T04:43:00.000 | 18 | 1 | 1 | 0 | python,c,utf-8,compression | 1,837,697 | 6 | false | 0 | 0 | Just use gzip compression, and save 60-70% with 0% effort! | 3 | 2 | 0 | I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB.
How would I go about doing this?
There doesn't seem to be an existing free or proprietary program to do so, so I was thinking I might try and make a simple(if inefficient) one.
The basic idea I have is to make a function from the current hex/decimal/binary values used for each character to the 128 values I would have in the seven bit encoding, then scan through the file and write each modified value to a new file.
So if the file looked like(I'll use a decimal example because I try not to have to think in hex)
127 254 025 212 015 015 132...
It would become
001 002 003 004 005 005 006
If 127 mapped to 001, 254 mapped to 005, etc.
I'm not entirely sure on a couple things, though.
Would this be enough to actually shorten the filesize? I have a bad feeling this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space.
If this would happen, how do I get rid of the zero?
How do I open the file to read/write in binary/decimal/hex rather than just text?
I've mostly worked with Python, but I can muddle through C if I must.
Thank you. | Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits | 1 | 0 | 0 | 2,837 |
1,837,686 | 2009-12-03T04:43:00.000 | 0 | 1 | 1 | 0 | python,c,utf-8,compression | 1,839,384 | 6 | false | 0 | 0 | "this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space."
Correct. Your plan will do nothing. | 3 | 2 | 0 | I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB.
How would I go about doing this?
There doesn't seem to be an existing free or proprietary program to do so, so I was thinking I might try and make a simple(if inefficient) one.
The basic idea I have is to make a function from the current hex/decimal/binary values used for each character to the 128 values I would have in the seven bit encoding, then scan through the file and write each modified value to a new file.
So if the file looked like(I'll use a decimal example because I try not to have to think in hex)
127 254 025 212 015 015 132...
It would become
001 002 003 004 005 005 006
If 127 mapped to 001, 254 mapped to 005, etc.
I'm not entirely sure on a couple things, though.
Would this be enough to actually shorten the filesize? I have a bad feeling this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space.
If this would happen, how do I get rid of the zero?
How do I open the file to read/write in binary/decimal/hex rather than just text?
I've mostly worked with Python, but I can muddle through C if I must.
Thank you. | Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits | 0 | 0 | 0 | 2,837 |
1,837,686 | 2009-12-03T04:43:00.000 | -2 | 1 | 1 | 0 | python,c,utf-8,compression | 1,838,614 | 6 | false | 0 | 0 | What you need is UTF-7.
Edit: UTF-7 has the advantage of bloating "only" special characters, so if special characters are rare in the input, you get far less bytes than by just converting UTF-8 to 7 bit. That's what UTF-7 is for. | 3 | 2 | 0 | I wish to take a file encoded in UTF-8 that doesn't use more than 128 different characters, then move it to a 7-bit encoding to save the 1/8 of space. For example, if I have a 16 MB text file that only uses the first 128(ascii) characters, I would like to shave off the extra bit to reduce the file to 14MB.
How would I go about doing this?
There doesn't seem to be an existing free or proprietary program to do so, so I was thinking I might try and make a simple(if inefficient) one.
The basic idea I have is to make a function from the current hex/decimal/binary values used for each character to the 128 values I would have in the seven bit encoding, then scan through the file and write each modified value to a new file.
So if the file looked like(I'll use a decimal example because I try not to have to think in hex)
127 254 025 212 015 015 132...
It would become
001 002 003 004 005 005 006
If 127 mapped to 001, 254 mapped to 005, etc.
I'm not entirely sure on a couple things, though.
Would this be enough to actually shorten the filesize? I have a bad feeling this would simply leave an extra 0 on the binary string--11011001 might get mapped to 01000001 rather than 1000001, and I won't actually save space.
If this would happen, how do I get rid of the zero?
How do I open the file to read/write in binary/decimal/hex rather than just text?
I've mostly worked with Python, but I can muddle through C if I must.
Thank you. | Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits | -0.066568 | 0 | 0 | 2,837 |
1,838,047 | 2009-12-03T06:26:00.000 | 0 | 0 | 0 | 0 | python | 1,870,291 | 3 | false | 1 | 0 | if you just want to download the image, theres two strategies you can try:
use a something like Firebug or Chrome developer tools. right click the element in question, click "inspect element", and look at the css properties of the element. if you look around, you should find something like background-image style or maybe just a normal tag. then you'll have the url to the image.
use a something like Firebug or Chrome developer tools: look in the "resources" tab, and look for image files that show up. | 2 | 0 | 0 | When I view the source of page, I do not find the image src. but the image is displayed on the page. This image is generated by some server side code.
I am using the selenium for testing. I want to download this image for verification/comparison.
How to get that image using python? | How to get the URL Image which is displyed by script | 0 | 0 | 1 | 163 |
1,838,047 | 2009-12-03T06:26:00.000 | 0 | 0 | 0 | 0 | python | 1,838,243 | 3 | false | 1 | 0 | If you aren't seeing an actual image tag in the HTML, your next step would seem to be figuring out how its being displayed.
The first place I'd suggest looking is in the .css files for this page. Images can actually be embedded using CSS, and this seems like the next likely option after being in the HTML code itself.
If it isn't in there, you may be dealing with some form of technique deliberately intended to prevent you from being able to download the image with a script. This may use obfuscated JavaScript or something similar and I wouldn't expect people to be able to give you an easy solution to bypass it (since it was carefully designed to resist exactly that). | 2 | 0 | 0 | When I view the source of page, I do not find the image src. but the image is displayed on the page. This image is generated by some server side code.
I am using the selenium for testing. I want to download this image for verification/comparison.
How to get that image using python? | How to get the URL Image which is displyed by script | 0 | 0 | 1 | 163 |
1,838,170 | 2009-12-03T06:57:00.000 | -1 | 0 | 1 | 0 | python,string,unicode,python-3.x | 1,838,285 | 8 | true | 0 | 0 | There has been NO CHANGE in Unicode internal representation between Python 2.X and 3.X.
It's definitely NOT UTF-16. UTF-anything is a byte-oriented EXTERNAL representation.
Each code unit (character, surrogate, etc) has been assigned a number from range(0, 2 ** 21). This is called its "ordinal".
Really, the documentation you quoted says it all. Most Python binaries use 16-bit ordinals which restricts you to the Basic Multilingual Plane ("BMP") unless you want to muck about with surrogates (handy if you can't find your hair shirt and your bed of nails is off being de-rusted). For working with the full Unicode repertoire, you'd prefer a "wide build" (32 bits wide).
Briefly, the internal representation in a unicode object is an array of 16-bit unsigned integers, or an array of 32-bit unsigned integers (using only 21 bits). | 2 | 36 | 0 | In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16?
The items of a string object are
Unicode code units. A Unicode code
unit is represented by a string object
of one item and can hold either a
16-bit or 32-bit value representing a
Unicode ordinal (the maximum value for
the ordinal is given in
sys.maxunicode, and depends on how
Python is configured at compile time).
Surrogate pairs may be present in the
Unicode object, and will be reported
as two separate items. | What is internal representation of string in Python 3.x | 1.2 | 0 | 0 | 16,363 |
1,838,170 | 2009-12-03T06:57:00.000 | 0 | 0 | 1 | 0 | python,string,unicode,python-3.x | 1,838,228 | 8 | false | 0 | 0 | I think, Its hard to judge difference between UTF-16, which is just a sequences of 16 bit words, to Python's string object.
And If python is compiled with Unicode=UCS4 option, it will be comparing between UTF-32 and Python string.
So, better consider, they are in different category, although you can transform each others. | 2 | 36 | 0 | In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16?
The items of a string object are
Unicode code units. A Unicode code
unit is represented by a string object
of one item and can hold either a
16-bit or 32-bit value representing a
Unicode ordinal (the maximum value for
the ordinal is given in
sys.maxunicode, and depends on how
Python is configured at compile time).
Surrogate pairs may be present in the
Unicode object, and will be reported
as two separate items. | What is internal representation of string in Python 3.x | 0 | 0 | 0 | 16,363 |
1,839,348 | 2009-12-03T11:28:00.000 | 1 | 1 | 0 | 1 | python,logging,pipe | 1,839,366 | 1 | true | 1 | 0 | Pipes are one of the fastest I/O mechanisms available. It's just a shared buffer. Nothing more. If the receiving end of your pipe is totally overwhelmed, you may have an issue. But you have no evidence of that right now.
If you have 10's of processes started by FastCGI, each can have their own independent log file. That's the ideal situation: use Python logging -- make each process have a unique log file.
In the rare event that you need to examine all log files, cat them together for analysis. | 1 | 0 | 0 | I'm writing a web app using python with web.py, and I want to implement my own logging system. I'd like to log detailed information about each request that come to python (static files are handled by web servers).
Currently I'm thinking about writing the logs to a pipe. On the other side, there should be cronolog.
My main concern is that will the performance be good? How is the time/resource consumed in piping the logs compared to the normal processing of a request (less than 5 database queries, and page generation from templates)?
Or are there other better approaches? I don't want to write the log file in python because tens of processes will be started by fastcgi. | python web app logging through pipe? (performance concerned) | 1.2 | 0 | 0 | 514 |
1,841,565 | 2009-12-03T17:34:00.000 | 15 | 0 | 1 | 0 | python,valueerror | 44,722,473 | 21 | false | 0 | 0 | The reason is that you are getting an empty string or a string as an argument into int. Check if it is empty or it contains alpha characters. If it contains characters, then simply ignore that part. | 6 | 561 | 0 | Why do I get this error?
ValueError: invalid literal for int() with base 10: ''. | ValueError: invalid literal for int() with base 10: '' | 1 | 0 | 0 | 2,671,706 |
1,841,565 | 2009-12-03T17:34:00.000 | 27 | 0 | 1 | 0 | python,valueerror | 55,803,849 | 21 | false | 0 | 0 | I found a work around. Python will convert the number to a float. Simply calling float first then converting that to an int will work:
output = int(float(input)) | 6 | 561 | 0 | Why do I get this error?
ValueError: invalid literal for int() with base 10: ''. | ValueError: invalid literal for int() with base 10: '' | 1 | 0 | 0 | 2,671,706 |
1,841,565 | 2009-12-03T17:34:00.000 | -2 | 0 | 1 | 0 | python,valueerror | 15,370,574 | 21 | false | 0 | 0 | I was getting similar errors, turns out that the dataset had blank values which python could not convert to integer. | 6 | 561 | 0 | Why do I get this error?
ValueError: invalid literal for int() with base 10: ''. | ValueError: invalid literal for int() with base 10: '' | -0.019045 | 0 | 0 | 2,671,706 |
1,841,565 | 2009-12-03T17:34:00.000 | 2 | 0 | 1 | 0 | python,valueerror | 24,059,374 | 21 | false | 0 | 0 | Please test this function (split()) on a simple file. I was facing the same issue and found that it was because split() was not written properly (exception handling). | 6 | 561 | 0 | Why do I get this error?
ValueError: invalid literal for int() with base 10: ''. | ValueError: invalid literal for int() with base 10: '' | 0.019045 | 0 | 0 | 2,671,706 |
1,841,565 | 2009-12-03T17:34:00.000 | -1 | 0 | 1 | 0 | python,valueerror | 53,628,251 | 21 | false | 0 | 0 | I got into the same issue when trying to use readlines() inside for loop for same file object... My suspicion is firing readling() inside readline() for same file object caused this error.
Best solution can be use seek(0) to reset file pointer or
Handle condition with setting some flag then create new object for same file by checking set condition.... | 6 | 561 | 0 | Why do I get this error?
ValueError: invalid literal for int() with base 10: ''. | ValueError: invalid literal for int() with base 10: '' | -0.009524 | 0 | 0 | 2,671,706 |
1,841,565 | 2009-12-03T17:34:00.000 | 0 | 0 | 1 | 0 | python,valueerror | 69,284,162 | 21 | false | 0 | 0 | I faced this error in Django - Once in my models I had a DateTimeField() with some saved objects on it.
then when I changed the field to DateField().
To solve this; I simply edited my Database(db.sqlite3) as I changed the date value from this format 2021-08-09 13:05:45 to this 2021-08-09, And that was all. | 6 | 561 | 0 | Why do I get this error?
ValueError: invalid literal for int() with base 10: ''. | ValueError: invalid literal for int() with base 10: '' | 0 | 0 | 0 | 2,671,706 |
1,841,737 | 2009-12-03T18:00:00.000 | 1 | 1 | 1 | 1 | python,perl,bash,hash,batch-processing | 1,847,365 | 13 | false | 0 | 0 | Hm, interesting problem.
Try the following (the mktest function is just for testing -- TDD for bash! :)
Edit:
Added support for whirlpool hashes.
code cleanup
better quoting of filenames
changed array-syntax for test part-- should now work with most korn-like shells. Note that pdksh does not support :-based parameter expansion (or rather
it means something else)
Note also that when in md5-mode it fails for filenames with whirlpool-like hashes, and
possibly vice-versa.
#!/usr/bin/env bash
#Tested with:
# GNU bash, version 4.0.28(1)-release (x86_64-pc-linux-gnu)
# ksh (AT&T Research) 93s+ 2008-01-31
# mksh @(#)MIRBSD KSH R39 2009/08/01 Debian 39.1-4
# Does not work with pdksh, dash
DEFAULT_SUM="md5"
#Takes a parameter, as root path
# as well as an optional parameter, the hash function to use (md5 or wp for whirlpool).
main()
{
case $2 in
"wp")
export SUM="wp"
;;
"md5")
export SUM="md5"
;;
*)
export SUM=$DEFAULT_SUM
;;
esac
# For all visible files in all visible subfolders, move the file
# to a name including the correct hash:
find $1 -type f -not -regex '.*/\..*' -exec $0 hashmove '{}' \;
}
# Given a file named in $1 with full path, calculate it's hash.
# Output the filname, with the hash inserted before the extention
# (if any) -- or: replace an existing hash with the new one,
# if a hash already exist.
hashname_md5()
{
pathname="$1"
full_hash=`md5sum "$pathname"`
hash=${full_hash:0:32}
filename=`basename "$pathname"`
prefix=${filename%%.*}
suffix=${filename#$prefix}
#If the suffix starts with something that looks like an md5sum,
#remove it:
suffix=`echo $suffix|sed -r 's/\.[a-z0-9]{32}//'`
echo "$prefix.$hash$suffix"
}
# Same as hashname_md5 -- but uses whirlpool hash.
hashname_wp()
{
pathname="$1"
hash=`whirlpool "$pathname"`
filename=`basename "$pathname"`
prefix=${filename%%.*}
suffix=${filename#$prefix}
#If the suffix starts with something that looks like an md5sum,
#remove it:
suffix=`echo $suffix|sed -r 's/\.[a-z0-9]{128}//'`
echo "$prefix.$hash$suffix"
}
#Given a filepath $1, move/rename it to a name including the filehash.
# Try to replace an existing hash, an not move a file if no update is
# needed.
hashmove()
{
pathname="$1"
filename=`basename "$pathname"`
path="${pathname%%/$filename}"
case $SUM in
"wp")
hashname=`hashname_wp "$pathname"`
;;
"md5")
hashname=`hashname_md5 "$pathname"`
;;
*)
echo "Unknown hash requested"
exit 1
;;
esac
if [[ "$filename" != "$hashname" ]]
then
echo "renaming: $pathname => $path/$hashname"
mv "$pathname" "$path/$hashname"
else
echo "$pathname up to date"
fi
}
# Create som testdata under /tmp
mktest()
{
root_dir=$(tempfile)
rm "$root_dir"
mkdir "$root_dir"
i=0
test_files[$((i++))]='test'
test_files[$((i++))]='testfile, no extention or spaces'
test_files[$((i++))]='.hidden'
test_files[$((i++))]='a hidden file'
test_files[$((i++))]='test space'
test_files[$((i++))]='testfile, no extention, spaces in name'
test_files[$((i++))]='test.txt'
test_files[$((i++))]='testfile, extention, no spaces in name'
test_files[$((i++))]='test.ab8e460eac3599549cfaa23a848635aa.txt'
test_files[$((i++))]='testfile, With (wrong) md5sum, no spaces in name'
test_files[$((i++))]='test spaced.ab8e460eac3599549cfaa23a848635aa.txt'
test_files[$((i++))]='testfile, With (wrong) md5sum, spaces in name'
test_files[$((i++))]='test.8072ec03e95a26bb07d6e163c93593283fee032db7265a29e2430004eefda22ce096be3fa189e8988c6ad77a3154af76f582d7e84e3f319b798d369352a63c3d.txt'
test_files[$((i++))]='testfile, With (wrong) whirlpoolhash, no spaces in name'
test_files[$((i++))]='test spaced.8072ec03e95a26bb07d6e163c93593283fee032db7265a29e2430004eefda22ce096be3fa189e8988c6ad77a3154af76f582d7e84e3f319b798d369352a63c3d.txt']
test_files[$((i++))]='testfile, With (wrong) whirlpoolhash, spaces in name'
test_files[$((i++))]='test space.txt'
test_files[$((i++))]='testfile, extention, spaces in name'
test_files[$((i++))]='test multi-space .txt'
test_files[$((i++))]='testfile, extention, multiple consequtive spaces in name'
test_files[$((i++))]='test space.h'
test_files[$((i++))]='testfile, short extention, spaces in name'
test_files[$((i++))]='test space.reallylong'
test_files[$((i++))]='testfile, long extention, spaces in name'
test_files[$((i++))]='test space.reallyreallyreallylong.tst'
test_files[$((i++))]='testfile, long extention, double extention,
might look like hash, spaces in name'
test_files[$((i++))]='utf8test1 - æeiaæå.txt'
test_files[$((i++))]='testfile, extention, utf8 characters, spaces in name'
test_files[$((i++))]='utf8test1 - 漢字.txt'
test_files[$((i++))]='testfile, extention, Japanese utf8 characters, spaces in name'
for s in . sub1 sub2 sub1/sub3 .hidden_dir
do
#note -p not needed as we create dirs top-down
#fails for "." -- but the hack allows us to use a single loop
#for creating testdata in all dirs
mkdir $root_dir/$s
dir=$root_dir/$s
i=0
while [[ $i -lt ${#test_files[*]} ]]
do
filename=${test_files[$((i++))]}
echo ${test_files[$((i++))]} > "$dir/$filename"
done
done
echo "$root_dir"
}
# Run test, given a hash-type as first argument
runtest()
{
sum=$1
root_dir=$(mktest)
echo "created dir: $root_dir"
echo "Running first test with hashtype $sum:"
echo
main $root_dir $sum
echo
echo "Running second test:"
echo
main $root_dir $sum
echo "Updating all files:"
find $root_dir -type f | while read f
do
echo "more content" >> "$f"
done
echo
echo "Running final test:"
echo
main $root_dir $sum
#cleanup:
rm -r $root_dir
}
# Test md5 and whirlpool hashes on generated data.
runtests()
{
runtest md5
runtest wp
}
#For in order to be able to call the script recursively, without splitting off
# functions to separate files:
case "$1" in
'test')
runtests
;;
'hashname')
hashname "$2"
;;
'hashmove')
hashmove "$2"
;;
'run')
main "$2" "$3"
;;
*)
echo "Use with: $0 test - or if you just want to try it on a folder:"
echo " $0 run path (implies md5)"
echo " $0 run md5 path"
echo " $0 run wp path"
;;
esac | 1 | 3 | 0 | Problem Specification:
Given a directory, I want to iterate through the directory and its non-hidden sub-directories,
and add a whirlpool hash into the non-hidden
file's names.
If the script is re-run it would would replace an old hash with a new one.
<filename>.<extension> ==> <filename>.<a-whirlpool-hash>.<extension>
<filename>.<old-hash>.<extension> ==> <filename>.<new-hash>.<extension>
Question:
a) How would you do this?
b) Out of the all methods available to you, what makes your method most suitable?
Verdict:
Thanks all, I have chosen SeigeX's answer for it's speed and portability.
It is emprically quicker than the other bash variants,
and it worked without alteration on my Mac OS X machine. | Hashing Multiple Files | 0.015383 | 0 | 0 | 4,430 |
1,842,208 | 2009-12-03T19:13:00.000 | 1 | 1 | 1 | 0 | php,python,linux,theory | 1,847,687 | 8 | false | 0 | 0 | If you're doing any multi threading development, pick Python over PHP. | 5 | 3 | 0 | I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.
Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform.
Edit 2: I'm hoping for objective answers, like a specific project, not a general field of projects, etc. | From a coder's perspective, what kind of project should I choose python over php for where both could do the job? | 0.024995 | 0 | 0 | 640 |
1,842,208 | 2009-12-03T19:13:00.000 | 1 | 1 | 1 | 0 | php,python,linux,theory | 1,845,431 | 8 | false | 0 | 0 | My company was contracted to build a web application last year, and the client specified that it should be done in Flex. Now, this application should have been a web application, but we had a unique opportunity to try something new.
We had absolutely no idea what we were doing at the time, but it was a great learning experience. My advice would be to try something new when you get the chance, make mistakes, and continue to learn.
Might be harder if you want to learn Python casually... Try getting someone to pay you for using it. | 5 | 3 | 0 | I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.
Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform.
Edit 2: I'm hoping for objective answers, like a specific project, not a general field of projects, etc. | From a coder's perspective, what kind of project should I choose python over php for where both could do the job? | 0.024995 | 0 | 0 | 640 |
1,842,208 | 2009-12-03T19:13:00.000 | 3 | 1 | 1 | 0 | php,python,linux,theory | 1,842,248 | 8 | false | 0 | 0 | A project you want to maintain over any length of time.
I've had to maintain PHP code and there is something about the fact that you can mix HTML and code that makes PHP stuff a nightmare.
Python has a much higher level of abstraction and makes more maintainable code much easier to write and much more importantly for maintenance - read.
All IMHO of course as this is a rather subjective question. | 5 | 3 | 0 | I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.
Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform.
Edit 2: I'm hoping for objective answers, like a specific project, not a general field of projects, etc. | From a coder's perspective, what kind of project should I choose python over php for where both could do the job? | 0.07486 | 0 | 0 | 640 |
1,842,208 | 2009-12-03T19:13:00.000 | 1 | 1 | 1 | 0 | php,python,linux,theory | 1,842,267 | 8 | false | 0 | 0 | Anything that requires background processing or any significant amount of code that doesn't just show a user a page. Python is really good as a scripting language, and writing a command line Python script is commonplace; writing a PHP script to do command line work is rare. | 5 | 3 | 0 | I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.
Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform.
Edit 2: I'm hoping for objective answers, like a specific project, not a general field of projects, etc. | From a coder's perspective, what kind of project should I choose python over php for where both could do the job? | 0.024995 | 0 | 0 | 640 |
1,842,208 | 2009-12-03T19:13:00.000 | 5 | 1 | 1 | 0 | php,python,linux,theory | 1,843,790 | 8 | false | 0 | 0 | PHP for websites. Python for pretty much anything else, such as commandline tools, long-running scripts, daemons, etcetera. If you're writing a PHP script and you're reaching for functions in the posix extenstion, shared memory or other low-level stuff then that's generally a sign that Python would be better suited. It's not that PHP can't do it, but Python just does it better and less buggy.
Especially when you're venturing into background daemons for your website you'll want to look at Python. PHP has some garbage collection problems in long running processes such as daemons. Also, some functionality is much easier and clearer in Python (e.g. redirecting STDIN, STDOUT and STDERR. PHP misses posix_dup2()). Also, Python has threads :-)
The only time when I now use PHP background daemons for my websites is when they can re-use significant amounts of code (such as with MVC frameworks like CakePHP).
One more advantage of Python is that there are many, many libraries for it, because it's rather easy to create a Python wrapper for a C library. So, Python has libraries that PHP doesn't have (OpenGL, multimedia, etcetera). So if you're into those areas Python becomes the obvious choice. | 5 | 3 | 0 | I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.
Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform.
Edit 2: I'm hoping for objective answers, like a specific project, not a general field of projects, etc. | From a coder's perspective, what kind of project should I choose python over php for where both could do the job? | 0.124353 | 0 | 0 | 640 |
1,842,360 | 2009-12-03T19:36:00.000 | 0 | 0 | 0 | 0 | python,facebook | 1,844,379 | 1 | true | 1 | 0 | The opening of a window for facebook auth is the way facebook set up their authentication for facebook connect.
I don't think they offer another way of authenticating users, and I doubt you'd be able to work-around/circumvent this method without breaking their terms of use
Sorry I don't have better news for you :/ | 1 | 0 | 0 | Is it possible for web application that is created by the same owner as facebook application to have access to facebook application without going through a explicit session opening exercise?
Most of the work is done on server side and I need to access facebook application directly from backend server. Each time the website loads I do not want user to go through the facebook connect experience as data to be displayed does not require his facebook profile/data access.
Let me know if its possible?
Although its not related to language, I would be grateful if help is provided keeping python in mind. Thx | Facebook login without opening another window/popup | 1.2 | 0 | 0 | 1,221 |
1,842,414 | 2009-12-03T19:47:00.000 | 62 | 0 | 1 | 0 | python,built-in,dir | 1,842,423 | 4 | true | 0 | 0 | It gives you a directory of all attributes of an object.
This is not a directory as used in file systems, but the standard usage: a listing of names or data. | 3 | 70 | 0 | In Python there is a built-in function called dir. This is used to get a list of all the attributes for an object.
I understand what it does, but I am confused about why it is called dir. How is this name related to getting the attributes from an object? | Why is 'dir()' named 'dir' in python? | 1.2 | 0 | 0 | 8,512 |
1,842,414 | 2009-12-03T19:47:00.000 | 96 | 0 | 1 | 0 | python,built-in,dir | 48,912,069 | 4 | false | 0 | 0 | IIRC I named it after the DIR command in DOS. | 3 | 70 | 0 | In Python there is a built-in function called dir. This is used to get a list of all the attributes for an object.
I understand what it does, but I am confused about why it is called dir. How is this name related to getting the attributes from an object? | Why is 'dir()' named 'dir' in python? | 1 | 0 | 0 | 8,512 |
1,842,414 | 2009-12-03T19:47:00.000 | 3 | 0 | 1 | 0 | python,built-in,dir | 1,842,428 | 4 | false | 0 | 0 | You're retrieving a "directory", a list of all of the stuff that's available in some resource. | 3 | 70 | 0 | In Python there is a built-in function called dir. This is used to get a list of all the attributes for an object.
I understand what it does, but I am confused about why it is called dir. How is this name related to getting the attributes from an object? | Why is 'dir()' named 'dir' in python? | 0.148885 | 0 | 0 | 8,512 |
1,842,593 | 2009-12-03T20:15:00.000 | 1 | 0 | 0 | 0 | python,django,timer | 1,842,622 | 3 | false | 1 | 0 | You should not use some in-process/memory timer objects since your django app can run in multiple processes...
I suggest create this "timers" in database (like "expire" datetime field for your product model) and use cron job that will mark expired objects to be available | 3 | 0 | 0 | I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, the product goes back to status "available". If the user completes the purchase, the timer should cancel, leaving the product's status permanently as "already taken".
I've tried using python's dictionary to instantiate python Timer objects of the fly, but about 30% of the time, I get a "key error" when it's time to cancel the Timer.
Please. Could someone give me an idea on the proper way to do this in Django?
Thanks very much!
Mark | Timer object in Django | 0.066568 | 0 | 0 | 2,462 |
1,842,593 | 2009-12-03T20:15:00.000 | -2 | 0 | 0 | 0 | python,django,timer | 1,842,666 | 3 | true | 1 | 0 | Fork it. Have your model use three states for a product: available, taken, and purchased. When a user initiates an action that marks the product as taken, spawn a new process that will mark the product to available in 3 minutes if it is not purchased. | 3 | 0 | 0 | I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, the product goes back to status "available". If the user completes the purchase, the timer should cancel, leaving the product's status permanently as "already taken".
I've tried using python's dictionary to instantiate python Timer objects of the fly, but about 30% of the time, I get a "key error" when it's time to cancel the Timer.
Please. Could someone give me an idea on the proper way to do this in Django?
Thanks very much!
Mark | Timer object in Django | 1.2 | 0 | 0 | 2,462 |
1,842,593 | 2009-12-03T20:15:00.000 | 6 | 0 | 0 | 0 | python,django,timer | 1,842,844 | 3 | false | 1 | 0 | I would not use a timer for such situation because it can give some complexity. What will happen to your timers if the process is restarted. That't the case with some internet providers who restart the process on a regular basis. Maybe you are facing a similar situation.
I would add a 'taken_time' datetimefield to your table to know when the product is taken and use it in order to know if the product is available or not
The list of available products would be filled with the 'available' products and the 'taken' if their 'taken_time' is lower than (current time - accepted delay)
I think you don't really need to change the status with an external process as long as you manage it correctly in your business logic.
I hope it helps
PS: Sorry for my english! Quite late in France now and difficult for me to find simple way to explain my view :-) | 3 | 0 | 0 | I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, the product goes back to status "available". If the user completes the purchase, the timer should cancel, leaving the product's status permanently as "already taken".
I've tried using python's dictionary to instantiate python Timer objects of the fly, but about 30% of the time, I get a "key error" when it's time to cancel the Timer.
Please. Could someone give me an idea on the proper way to do this in Django?
Thanks very much!
Mark | Timer object in Django | 1 | 0 | 0 | 2,462 |
1,842,798 | 2009-12-03T20:44:00.000 | 1 | 0 | 1 | 1 | python,windows,performance,macos,mercurial | 1,845,290 | 6 | false | 0 | 0 | I run Python locally on Windows XP and 7 as well as OSX on my Macbook. I've seen no noticable performance differences in the command line interpreter, wx widget apps run the same, and Django apps also perform virtually identically.
One thing I noticed at work was that the Kaspersky virus scanner tended to slow the python interpreter WAY down. It would take 3-5 seconds for the python prompt to properly appear and 7-10 seconds for Django's test server to fully load. Properly disabling its active scanning brought the start up times back to 0 seconds. | 5 | 13 | 0 | Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it seems to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory.
I particularly notice this in Mercurial but I figure this may simply be how Mercurial is packaged on windows. | Python Performance on Windows | 0.033321 | 0 | 0 | 9,943 |
1,842,798 | 2009-12-03T20:44:00.000 | 1 | 0 | 1 | 1 | python,windows,performance,macos,mercurial | 1,845,271 | 6 | false | 0 | 0 | Maybe the python has more depend on a lot of files open (import different modules).
Windows doesn't handle file open as efficiently as Linux.
Or maybe Linux probably have more utilities depend on python and python scripts/modules are more likely to be buffered in the system cache. | 5 | 13 | 0 | Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it seems to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory.
I particularly notice this in Mercurial but I figure this may simply be how Mercurial is packaged on windows. | Python Performance on Windows | 0.033321 | 0 | 0 | 9,943 |
1,842,798 | 2009-12-03T20:44:00.000 | 0 | 0 | 1 | 1 | python,windows,performance,macos,mercurial | 37,372,277 | 6 | false | 0 | 0 | Interestingly I ran a direct comparison of a popular Python app on a Windows 10 x64 Machine (low powered admittedly) and a Ubuntu 14.04 VM running on the same machine.
I have not tested load speeds etc, but am just looking at processor usage between the two. To make the test fair, both were fresh installs and I duplicated a part of my media library and applied the same config in both scenarios. Each test was run independently.
On Windows Python was using 20% of my processor power and it triggered System Compressed Memory to run up at 40% (this is an old machine with 6GB or RAM).
With the VM on Ubuntu (linked to my windows file system) the processor usage is about 5% with compressed memory down to about 20%.
This is a huge difference. My trigger for running this test was that the app using python was running my CPU up to 100% and failing to operate. I have now been running it in the VM for 2 weeks and my processor usage is down to 65-70% on average. So both on a long and short term test, and taking into account the overhead of running a VM and second operating system, this Python app is significantly faster on Linux. I can also confirm that the Python app responds better, as does everything else on my machine.
Now this could be very application specific, but it is at minimum interesting.
The PC is an old AMD II X2 X265 Processor, 6GB of RAM, SSD HD (which Python ran from but the VM used a regular 5200rpm HD which gets used for a ton of other stuff including recording of 2 CCTV cameras). | 5 | 13 | 0 | Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it seems to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory.
I particularly notice this in Mercurial but I figure this may simply be how Mercurial is packaged on windows. | Python Performance on Windows | 0 | 0 | 0 | 9,943 |
1,842,798 | 2009-12-03T20:44:00.000 | 1 | 0 | 1 | 1 | python,windows,performance,macos,mercurial | 1,843,044 | 6 | false | 0 | 0 | No real numbers here but it certainly feels like the start up time is slower on Windows platforms. I regularly switch between Ubuntu at home and Windows 7 at work and it's an order of magnitude faster starting up on Ubuntu, despite my work machine being at least 4x the speed.
As for runtime performance, it feels about the same for "quiet" applications. If there are any GUI operations using Tk on Windows, they are definitely slower. Any console applications on windows are slower, but this is most likely due to the Windows cmd rendering being slow more than python running slowly. | 5 | 13 | 0 | Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it seems to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory.
I particularly notice this in Mercurial but I figure this may simply be how Mercurial is packaged on windows. | Python Performance on Windows | 0.033321 | 0 | 0 | 9,943 |
1,842,798 | 2009-12-03T20:44:00.000 | 0 | 0 | 1 | 1 | python,windows,performance,macos,mercurial | 1,846,141 | 6 | false | 0 | 0 | With the OS and network libraries, I can confirm slower performance on Windows, at least for versions =< 2.6.
I wrote a CLI podcast-fetcher script which ran great on Ubuntu, but then wouldn't download anything faster than about 80 kB/s (where ~1.6 MB/s is my usual max) on either XP or 7.
I could partially correct this by tweaking the buffer size for download streams, but there was definitely a major bottleneck on Windows, either over the network or IO, that simply wasn't a problem on Linux.
Based on this, it seems that system and OS-interfacing tasks are better optimized for *nixes than they are for Windows. | 5 | 13 | 0 | Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it seems to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory.
I particularly notice this in Mercurial but I figure this may simply be how Mercurial is packaged on windows. | Python Performance on Windows | 0 | 0 | 0 | 9,943 |
1,843,219 | 2009-12-03T21:57:00.000 | 0 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,265 | 16 | false | 0 | 0 | I'm not too familiar with Python so I'll give some general advice. Make sure to print out some reference pages of common functions. Keep them by you(or pinned to a wall or desk) at all times when your programming.. I'm traditionally a "stone age" developer and after developing in VS for a few months I'm finding my hobby programming is difficult without intellisense.. but keep at it to memorize the most common functions and eventually it'll just be natural
You'll also have to get use to a bit more "difficult" of debugging(not sure how that works with python)
While your learning though, you should enjoy the goodness(at least compared to C#) of Python even if you don't have intellisense.. hopefully this will motivate you! | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 2 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,298 | 16 | false | 0 | 0 | You could always start with IronPython and continue to develop in Visual Studio. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.024995 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 1 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,844,168 | 16 | false | 0 | 0 | Same way you do anything else that doesn't have IntelliStuff.
I'm betting you wrote that question without the aid of an IntelliEnglish computer program that showed you a list of verbs you could use and automatically added punctuation at the end of your sentences, for example. :-) | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.012499 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 0 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,273 | 16 | false | 0 | 0 | I've only ever used IDLE for python development and it is not fun in the least. I would recommend getting your favorite text editor, mine is notepad++, and praying for a decent plugin for it. I only ever had to go from Eclipse to Visual Studio so my opinions are generally invalid in these contexts. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 5 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,269 | 16 | false | 0 | 0 | One step at a time?
Start off with simple programs (things you can write with your eyes closed in C#), and keep going... You will end up knowing the API by heart. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.062419 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 1 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,406 | 16 | false | 0 | 0 | Don't worry about intellisense. Python is really simple and there really isn't that much to know, so after a few projects you'll be conceiving of python code while driving, eating, etc., without really even trying. Plus, python's built in text editor (IDLE) has a wimpy version of intellisense that has always been more than sufficient for my purposes. If you ever go blank and want to know what methods/properties and object has, just type this in an interactive session:
dir(myobject) | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.012499 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 2 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,362 | 16 | false | 0 | 0 | The python ide from wingware is pretty nice. Thats what I ended up using going from visual studio C++/.net to doing python. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.024995 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 4 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,843,434 | 16 | false | 0 | 0 | <rant>
This is sort of the reason that I think being a good visual studio user makes you a bad developer. Instead of learning an API, you look in the object browser until you find something that sounds more or less like what you are looking for, instantiate it, then hit . and start looking for what sounds like the right thing to use. While this is very quick, it also means it takes forever to learn an API in any depth, which often means you end up either re-inventing the wheel (because the wheel is buried under a mountain worth of household appliances and you had no idea it was there), or just doing things in a sub-optimal way. Just because you can find A solution quickly, doesn't mean it is THE BEST solution.
</rant>
In the case of .NET, which ships with about a billion APIs for everything under the sun, this is actually preferred. You need to sift through a lot of noise to find what you are aiming for.
Pythonic code favors one, obvious way to do any given thing. This tends to make the APIs very straight forward and readable. The trick is to learn the language and learn the APIs. It is not terribly hard to do, especially in the case of python, and while not being able to rely on intellisense may be jarring at first, it shouldn't take more then a week or two before you get used to it not being there.
Learn the language and the basic standard libraries with a good book. When it comes to a new library API, I find the REPL and some exploratory coding can get me to a pretty good understanding of what is going on fairly quickly. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.049958 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 0 | 0 | 1 | 0 | c#,python,visual-studio,transition | 1,847,072 | 16 | false | 0 | 0 | I suggest going cold turkey - languages like Python shine with great text editors. Choose one you want to become amazing at (vim, emacs, etc.) and never look back. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0 | 0 | 0 | 10,335 |
1,843,219 | 2009-12-03T21:57:00.000 | 1 | 0 | 1 | 0 | c#,python,visual-studio,transition | 38,883,895 | 16 | false | 0 | 0 | A mistake people coming from C# or Java make a lot is recreate a large class hierarchy like is common in those languages. With Python this is almost never useful. Instead, learn about duck typing. And don't worry too much about the lack of static typing: in practice, it's almost never an issue. | 10 | 9 | 0 | i feel like i'm going back to the stone age.
how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ? | how to transition from C# to python? | 0.012499 | 0 | 0 | 10,335 |
1,844,630 | 2009-12-04T03:19:00.000 | 4 | 0 | 0 | 0 | python,qt4,pyqt | 1,844,678 | 2 | true | 0 | 1 | The easy solution would be to have an interior widget, not an interior layout. You could assign the layout you desire to the widget, then just remove/hide the widget when you want to do so. A good rule of thumb is if you just want to arrange how widgets appear, then use a layout; if you want to hide/show them as a group, use a widget. | 1 | 3 | 0 | In PyQt 4.5, I have a layout inside another layout. I'd like to remove the sublayout from its parent, and hide it. I can say parent_layout.removeItem(child_layout) to remove the layout from its parent, but it still shows on the widget. I can't find any way to hide it in one step, as QLayout doesn't have a hide() method like QWidget does. | Remove a sublayout in qt? | 1.2 | 0 | 0 | 2,317 |
1,847,120 | 2009-12-04T14:02:00.000 | 0 | 0 | 0 | 0 | javascript,python,xmpp,wsgi | 1,881,020 | 3 | false | 1 | 0 | I have found a lot of issues with Openfire and TLS are not with the xmpp lib :( -- SleekXMPP in the trunk has been converted to Python 3.0 and the branch is maintained for Python 2.5
Unlike Julien, I would only go with Twisted Words if you really need the power of Twisted or if you are already using Twisted. IMO SleekXMPP offers the closest match to the current XEP's in use today. | 1 | 3 | 0 | I want to learn how to use XMPP and to create a simple web application with real collaboration features.
I am writing the application with Python(WSGI), and the application will require javascript enabled because I am going to use jQuery or Dojo.
I have downloaded Openfire for the server and which lib to choose? SleekXMPP making trouble with tlslite module(python 2.5 and I need only python 2.6).
What is your suggestion? | Best XMPP Library for Python Web Application | 0 | 0 | 1 | 1,373 |
1,847,534 | 2009-12-04T15:06:00.000 | 3 | 0 | 0 | 0 | c#,python,web-services,xml-rpc | 1,847,560 | 4 | false | 0 | 0 | They are completely different protocols, you need to find out the protocol used by the web service you wish to consume and program to that. Web services is really just a concept XML-RPC, SOAP and REST are actual technologies the implement this concept. These implementations are not interoperable (without some translation layer).
All these protocols enable basically the same sort of thing, calling into remote some application over the web. However the details of how they do this differ, they are not just different names for the same protocol. | 3 | 3 | 0 | Are they just the same protocol or something different?
I am just confused about it.
Actually, I want to call a web service written in C# with ASP.NET by Python. I have tried XMLRPC but it seems just did not work.
So what is the actually difference among them?
Thanks. | Can anyone explain the difference between XMLRPC, SOAP and also the C# Web Service? | 0.148885 | 0 | 1 | 2,232 |
1,847,534 | 2009-12-04T15:06:00.000 | 5 | 0 | 0 | 0 | c#,python,web-services,xml-rpc | 1,847,573 | 4 | true | 0 | 0 | All of them use the same transport protocol (HTTP).
XMLRPC formats a traditional RPC call with XML for remote execution.
SOAP wraps the call in a SOAP envelope (still XML, different formatting, oriented towards message based services rather than RPC style calls).
If you're using C#, your best bet is probably SOAP based Web Services (at least out of the options you listed). | 3 | 3 | 0 | Are they just the same protocol or something different?
I am just confused about it.
Actually, I want to call a web service written in C# with ASP.NET by Python. I have tried XMLRPC but it seems just did not work.
So what is the actually difference among them?
Thanks. | Can anyone explain the difference between XMLRPC, SOAP and also the C# Web Service? | 1.2 | 0 | 1 | 2,232 |
1,847,534 | 2009-12-04T15:06:00.000 | 1 | 0 | 0 | 0 | c#,python,web-services,xml-rpc | 3,913,857 | 4 | false | 0 | 0 | xml-rpc: Its a mechanism to call remote procedure & function accross network for distributed system integration. It uses XML based message document and HTTP as transport protocol. Further, it only support 6 basic data type as well as array for communication.
SOAP: SOAP is also XML-based protocol for information exchange using HTPP transport protocol. However, it is more advanced then XML-RPC protocol. It uses XML formatted message that helps communicating complex data types accross distributed application, and hence is widely used now a days. | 3 | 3 | 0 | Are they just the same protocol or something different?
I am just confused about it.
Actually, I want to call a web service written in C# with ASP.NET by Python. I have tried XMLRPC but it seems just did not work.
So what is the actually difference among them?
Thanks. | Can anyone explain the difference between XMLRPC, SOAP and also the C# Web Service? | 0.049958 | 0 | 1 | 2,232 |
1,848,464 | 2009-12-04T17:28:00.000 | 2 | 0 | 1 | 0 | python,pdf,parsing,text-extraction,information-extraction | 1,850,290 | 2 | false | 0 | 0 | That's a difficult problem to solve since visually similar PDFs may have a wildly differing structure depending on how they were produced. In the worst case the library would need to basically act like an OCR. On the other hand, the PDF may contain sufficient structure and metadata for easy removal of tables and figures, which the library can be tailored to take advantage of.
I'm pretty sure there are no open source tools which solve your problem for a wide variety of PDFs, but I remember having heard of commercial software claiming to do exactly what you ask for. I'm sure you'll run into them while googling. | 1 | 83 | 0 | I'm looking for a PDF library which will allow me to extract the text from a PDF document. I've looked at PyPDF, and this can extract the text from a PDF document very nicely. The problem with this is that if there are tables in the document, the text in the tables is extracted in-line with the rest of the document text. This can be problematic because it produces sections of text that aren't useful and look garbled (for instance, lots of numbers mashed together).
I'd like to extract the text from a PDF document, excluding any tables and special formatting. Is there a library out there that does this? | PDF Parsing Using Python - extracting formatted and plain texts | 0.197375 | 0 | 0 | 126,787 |
1,849,324 | 2009-12-04T20:03:00.000 | 2 | 0 | 1 | 0 | python,algorithm,dictionary,hash | 1,849,328 | 7 | false | 0 | 0 | A Python dictionary has no concept of order. So you can't depend on a specific order while iterating.
This is deliberate: since it's a hashmap it's unavoidable if you want 'fast lookups'! | 3 | 19 | 0 | If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups). | Do dicts preserve iteration order if they are not modified? | 0.057081 | 0 | 0 | 4,350 |
1,849,324 | 2009-12-04T20:03:00.000 | 3 | 0 | 1 | 0 | python,algorithm,dictionary,hash | 1,849,367 | 7 | false | 0 | 0 | It might be preserved in some implementations, but don't count on it, as it is not a part of the Dict spec. | 3 | 19 | 0 | If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups). | Do dicts preserve iteration order if they are not modified? | 0.085505 | 0 | 0 | 4,350 |
1,849,324 | 2009-12-04T20:03:00.000 | 1 | 0 | 1 | 0 | python,algorithm,dictionary,hash | 1,849,368 | 7 | false | 0 | 0 | As Christophe said, a dictionary is used to organise key/value pairs because of the fast access time it provides. If you application needs a fixed index, you should look at the other data structures that provide a specific/known order.
Having said that, it should be safe to assume that the order doesn't change unless items are added (there wouldn't be any point to do this expensive operation of reshuffling stuff) etc but, again, don't rely on it. | 3 | 19 | 0 | If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups). | Do dicts preserve iteration order if they are not modified? | 0.028564 | 0 | 0 | 4,350 |
1,849,376 | 2009-12-04T20:12:00.000 | 1 | 1 | 1 | 0 | python,ruby,programming-languages,language-features,language-design | 1,871,126 | 4 | false | 0 | 0 | Python's import provides a very explicit kind of namespace: the namespace is the path, you don't have to look into files to know what namespace they do their definitions in, and your file is not cluttered with namespace definitions. This makes the namespace scheme of an application simple and fast to understand (just look at the source tree), and avoids simple mistakes like mistyping a namespace declaration.
A nice side effect is every file has its own private namespace, so you don't have to worry about conflicts when naming things.
Sometimes namespaces can get annoying too, having things like some.module.far.far.away.TheClass() everywhere can quickly make your code very long and boring to type. In these cases you can import ... from ... and inject bits of another namespace in the current one. If the injection causes a conflict with the module you are importing in, you can simply rename the thing you imported: from some.other.module import Bar as BarFromOtherModule.
Python is still vulnerable to problems like circular imports, but it's the application design more than the language that has to be blamed in these cases.
So python took C++ namespace and #include and largely extended on it. On the other hand I don't see in which way ruby's module and require add anything new to these, and you have the exact same horrible problems like global namespace cluttering. | 2 | 9 | 0 | Ruby uses require, Python uses import. They're substantially different models, and while I'm more used to the require model, I can see a few places where I think I like import more. I'm curious what things people find particularly easy — or more interestingly, harder than they should be — with each of these models.
In particular, if you were writing a new programming language, how would you design a code-loading mechanism? Which "pros" and "cons" would weigh most heavily on your design choice? | What are the advantages and disadvantages of the require vs. import methods of loading code? | 0.049958 | 0 | 0 | 6,271 |
1,849,376 | 2009-12-04T20:12:00.000 | 4 | 1 | 1 | 0 | python,ruby,programming-languages,language-features,language-design | 1,870,801 | 4 | false | 0 | 0 | A nice property of require is that it is actually a method defined in Kernel. Thus you can override it and implement your own packaging system for Ruby, which is what e.g. Rubygems does!
PS: I am not selling monkey patching here, but the fact that Ruby's package system can be rewritten by the user (even to work like python's system). When you write a new programming language, you cannot get everything right. Thus if your import mechanism is fully extensible (into totally all directions) from within the language, you do your future users the best service. A language that is not fully extensible from within itself is an evolutionary dead-end. I'd say this is one of the things Matz got right with Ruby. | 2 | 9 | 0 | Ruby uses require, Python uses import. They're substantially different models, and while I'm more used to the require model, I can see a few places where I think I like import more. I'm curious what things people find particularly easy — or more interestingly, harder than they should be — with each of these models.
In particular, if you were writing a new programming language, how would you design a code-loading mechanism? Which "pros" and "cons" would weigh most heavily on your design choice? | What are the advantages and disadvantages of the require vs. import methods of loading code? | 0.197375 | 0 | 0 | 6,271 |
1,849,447 | 2009-12-04T20:26:00.000 | -1 | 0 | 1 | 0 | c++,python,regex,algorithm,overlap | 1,849,615 | 3 | false | 0 | 0 | In theory, the problem you describe is impossible.
In practice, if you have a manageable number of regular expressions that use a limited subset or of regexp syntax, and/or a limited selection of strings that can be used to match against the container of regular expressions, you might be able to solve it.
Assuming you're not trying to solve the abstract general case, there might be something you can do to solve a practical application. Perhaps if you provided a representative sample of the regexps, and described the strings you'd be matching with, a heuristic could be created to solve the problem. | 1 | 28 | 0 | I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? | How can you detect if two regular expressions overlap in the strings they can match? | -0.066568 | 0 | 0 | 5,839 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.