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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
315,435 |
2008-11-24T20:53:00.000
| 0 | 0 | 1 | 0 |
python,reversi
| 319,927 | 6 | false | 0 | 0 |
You may also wish to consider the application of a "fuzzy logic" loop to analyze positions. Reversi/Othello is notorious for forcing players to consider certain strategic gains against strategic losses for each move, as well as prioritizing one positive move over another.
A fuzzy system would give you greater control over testing move selection by setting various settings against each other, as well as giving you the ability to create multiple "personalities" to play against by shifting the various weights.
| 3 | 3 | 0 |
I am trying to write Reversi game in Python. Can anyone give me some basic ideas and strategy which are simple, good and easy to use?
I would appreciate for any help because I've gone to a little far but is stucked between codes and it became more complex too. I think I overdid in some part that should be fairly simple. So....
|
Need instructions for Reversi game
| 0 | 0 | 0 | 3,730 |
315,435 |
2008-11-24T20:53:00.000
| 0 | 0 | 1 | 0 |
python,reversi
| 315,515 | 6 | false | 0 | 0 |
You'll need a 2D array. Beware of [[0] * 8] * 8, instead use [[0 for _ in [0] * 8] for _ in [0] * 8]
White should be 1 and black -1 (Or vice versa, of course). This way you can do flips with *=-1 and keep blank blank
Double four loops will be able to total scores and determine if the game is done pretty well. map(sum,map(sum,board)) will give you the net score
Don't forget to check and see if the player can even move at the beginning of a round
| 3 | 3 | 0 |
I am trying to write Reversi game in Python. Can anyone give me some basic ideas and strategy which are simple, good and easy to use?
I would appreciate for any help because I've gone to a little far but is stucked between codes and it became more complex too. I think I overdid in some part that should be fairly simple. So....
|
Need instructions for Reversi game
| 0 | 0 | 0 | 3,730 |
315,716 |
2008-11-24T22:21:00.000
| 3 | 0 | 0 | 1 |
python,tcp,twisted,protocols
| 315,855 | 2 | false | 0 | 0 |
I'd imagine the easiest way to do that is to manage a list of clients in the protocol with connectionMade and connectionLost in the client and then use a LoopingCall to ask each client to send data.
That feels a little invasive, but I don't think you'd want to do it without the protocol having some control over the transmission/reception. Of course, I'd have to see your code to really know how it'd fit in well. Got a github link? :)
| 1 | 24 | 0 |
I am looking for a way to periodically send some data over all clients connected to a TCP port. I am looking at twisted python and I am aware of reactor.callLater. But how do I use it to send some data to all connected clients periodically ? The data sending logic is in Protocol class and it is instantiated by the reactor as needed. I don't know how to tie it from reactor to all protocol instances...
|
Running a function periodically in twisted protocol
| 0.291313 | 0 | 0 | 8,021 |
316,238 |
2008-11-25T02:53:00.000
| 30 | 0 | 1 | 0 |
python,decimal
| 316,308 | 11 | false | 0 | 0 |
You said in your question:
Can someone suggest a good way to
convert from float to Decimal
preserving value as the user has
entered
But every time the user enters a value, it is entered as a string, not as a float. You are converting it to a float somewhere. Convert it to a Decimal directly instead and no precision will be lost.
| 4 | 76 | 0 |
Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first.
This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as many as 15 decimal places you need to format as Decimal("%.15f" % my_float), which will give you garbage at the 15th decimal place if you also have any significant digits before decimal (Decimal("%.15f" % 100000.3) == Decimal('100000.300000000002910')).
Can someone suggest a good way to convert from float to Decimal preserving value as the user has entered, perhaps limiting number of significant digits that can be supported?
|
Python float to Decimal conversion
| 1 | 0 | 0 | 116,354 |
316,238 |
2008-11-25T02:53:00.000
| 5 | 0 | 1 | 0 |
python,decimal
| 342,356 | 11 | false | 0 | 0 |
Python does support Decimal creation from a float. You just cast it as a string first. But the precision loss doesn't occur with string conversion. The float you are converting doesn't have that kind of precision in the first place. (Otherwise you wouldn't need Decimal)
I think the confusion here is that we can create float literals in decimal format, but as soon as the interpreter consumes that literal the inner representation becomes a floating point number.
| 4 | 76 | 0 |
Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first.
This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as many as 15 decimal places you need to format as Decimal("%.15f" % my_float), which will give you garbage at the 15th decimal place if you also have any significant digits before decimal (Decimal("%.15f" % 100000.3) == Decimal('100000.300000000002910')).
Can someone suggest a good way to convert from float to Decimal preserving value as the user has entered, perhaps limiting number of significant digits that can be supported?
|
Python float to Decimal conversion
| 0.090659 | 0 | 0 | 116,354 |
316,238 |
2008-11-25T02:53:00.000
| 2 | 0 | 1 | 0 |
python,decimal
| 62,046,166 | 11 | false | 0 | 0 |
The main answer is slightly misleading. The g format ignores any leading zeroes after the decimal point, so format(0.012345, ".2g") returns 0.012 - three decimal places. If you need a hard limit on the number of decimal places, use the f formatter: format(0.012345, ".2f") == 0.01
| 4 | 76 | 0 |
Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first.
This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as many as 15 decimal places you need to format as Decimal("%.15f" % my_float), which will give you garbage at the 15th decimal place if you also have any significant digits before decimal (Decimal("%.15f" % 100000.3) == Decimal('100000.300000000002910')).
Can someone suggest a good way to convert from float to Decimal preserving value as the user has entered, perhaps limiting number of significant digits that can be supported?
|
Python float to Decimal conversion
| 0.036348 | 0 | 0 | 116,354 |
316,238 |
2008-11-25T02:53:00.000
| 2 | 0 | 1 | 0 |
python,decimal
| 316,313 | 11 | false | 0 | 0 |
When you say "preserving value as the user has entered", why not just store the user-entered value as a string, and pass that to the Decimal constructor?
| 4 | 76 | 0 |
Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first.
This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as many as 15 decimal places you need to format as Decimal("%.15f" % my_float), which will give you garbage at the 15th decimal place if you also have any significant digits before decimal (Decimal("%.15f" % 100000.3) == Decimal('100000.300000000002910')).
Can someone suggest a good way to convert from float to Decimal preserving value as the user has entered, perhaps limiting number of significant digits that can be supported?
|
Python float to Decimal conversion
| 0.036348 | 0 | 0 | 116,354 |
316,484 |
2008-11-25T06:14:00.000
| 2 | 0 | 0 | 0 |
python,mysql,winapi
| 317,716 | 4 | true | 0 | 0 |
I think that the header files are shipped with MySQL, just make sure you check the appropriate options when installing (I think that sources and headers are under "developer components" in the installation dialog).
| 1 | 9 | 0 |
I'm using Django and Python 2.6, and I want to grow my application using a MySQL backend. Problem is that there isn't a win32 package for MySQLdb on Python 2.6.
Now I'm no hacker, but I thought I might compile it myself using MSVC++9 Express. But I run into a problem that the compiler quickly can't find config_win.h, which I assume is a header file for MySQL so that the MySQLdb package can know what calls it can make into MySQL.
Am I right? And if so, where do I get the header files for MySQL?
|
Problem compiling MySQLdb for Python 2.6 on Win32
| 1.2 | 1 | 0 | 3,446 |
316,518 |
2008-11-25T06:41:00.000
| 1 | 1 | 0 | 1 |
python,jython,tiff,ghostscript
| 317,300 | 1 | false | 0 | 0 |
It may be that you need to read stderr from the child process.
| 1 | 0 | 0 |
Ghostscript curls up and dies, throwing an exception to stdout which I cannot catch and log. I am pretty sure it gets sick when I give it asian fonts. Has anybody backed into this problem and solved it?
|
Ghostscript PDF -> TIFF throws an untrappable exception, when consuming files with asian fonts
| 0.197375 | 0 | 0 | 416 |
318,390 |
2008-11-25T18:23:00.000
| 1 | 0 | 1 | 0 |
python,numpy
| 318,422 | 4 | false | 0 | 0 |
You're running a separate copy of python provided by cygwin.
You can run /cygdrive/c/python25/python (or wherever you installed it)
to get your win32 one, or just install another copy of numpy.
| 3 | 2 | 0 |
I am running a windows machine have installed Python 2.5. I also used the windows installer to install NumPy.
This all works great when I run the Python (command line) tool that comes with Python.
However, if I run cygwin and then run Python from within, it cannot find the numpy package.
What environment variable do I need to set? What value should it be set to?
|
Running numpy from cygwin
| 0.049958 | 0 | 0 | 9,602 |
318,390 |
2008-11-25T18:23:00.000
| 4 | 0 | 1 | 0 |
python,numpy
| 318,419 | 4 | true | 0 | 0 |
Cygwin comes with its own version of Python, so it's likely that you have two Python installs on your system; one that installed under Windows and one which came with Cygwin.
To test this, try opening a bash prompt in Cygwin and typing which python to see where the Python executable is located. If it says /cygdrive/c/Python25/python.exe or something similar then you'll know you're running the Windows executable. If you see /usr/local/bin/python or something like that, then you'll know that you're running the Cygwin version.
I recommend opening a DOS prompt and running Python from there when you need interactive usage. This will keep your two Python installs nicely separate (it can be very useful to have both; I do this on my own machine). Also, you may have some problems running a program designed for Windows interactive console use from within a Cygwin shell.
| 3 | 2 | 0 |
I am running a windows machine have installed Python 2.5. I also used the windows installer to install NumPy.
This all works great when I run the Python (command line) tool that comes with Python.
However, if I run cygwin and then run Python from within, it cannot find the numpy package.
What environment variable do I need to set? What value should it be set to?
|
Running numpy from cygwin
| 1.2 | 0 | 0 | 9,602 |
318,390 |
2008-11-25T18:23:00.000
| 0 | 0 | 1 | 0 |
python,numpy
| 798,145 | 4 | false | 0 | 0 |
numpy built for windows is not compatible with cygwin python. You have to build it by yourself on cygwin.
| 3 | 2 | 0 |
I am running a windows machine have installed Python 2.5. I also used the windows installer to install NumPy.
This all works great when I run the Python (command line) tool that comes with Python.
However, if I run cygwin and then run Python from within, it cannot find the numpy package.
What environment variable do I need to set? What value should it be set to?
|
Running numpy from cygwin
| 0 | 0 | 0 | 9,602 |
319,232 |
2008-11-25T23:14:00.000
| 1 | 0 | 1 | 0 |
python,assembly
| 327,529 | 2 | false | 0 | 0 |
It's certainly doable, but you'd have a much easier time reading the C API docs and writing a go-between function in C.
Come to think of it, C is highly recommended, since it may be hard to tell which of the routines you're calling might be implemented as preprocessor macros.
| 1 | 2 | 0 |
I'll have couple of python functions I must interface with from the assembly code. The solution doesn't need to be a complete solution because I'm not going to interface with python code for too long. Anyway, I chewed it a bit:
What does a python object look like in memory?
How can I call a python function?
How can I pass python objects as python objects for ctypes interface?
Could ctypes interface make my work easier in any alternative way?
|
How to call python2.5 function from x86asm/x64asm?
| 0.099668 | 0 | 0 | 126 |
319,279 |
2008-11-25T23:40:00.000
| 0 | 0 | 1 | 0 |
python,validation,networking,ip-address
| 17,214,916 | 11 | false | 0 | 0 |
I only needed to parse IP v4 addresses. My solution based on Chills strategy follows:
def getIP():
valid = False
while not valid :
octets = raw_input( "Remote Machine IP Address:" ).strip().split(".")
try: valid=len( filter( lambda(item):0<=int(item)<256, octets) ) == 4
except: valid = False
return ".".join( octets )
| 1 | 175 | 0 |
What's the best way to validate that an IP entered by the user is valid? It comes in as a string.
|
How to validate IP address in Python?
| 0 | 0 | 1 | 305,361 |
319,426 |
2008-11-26T01:06:00.000
| 2 | 0 | 1 | 0 |
python,comparison,case-insensitive
| 319,439 | 12 | false | 0 | 0 |
How about converting to lowercase first? you can use string.lower().
| 1 | 700 | 0 |
How can I do case insensitive string comparison in Python?
I would like to encapsulate comparison of a regular strings to a repository string using in a very simple and Pythonic way. I also would like to have ability to look up values in a dict hashed by strings using regular python strings.
|
How do I do a case-insensitive string comparison?
| 0.033321 | 0 | 0 | 984,158 |
319,896 |
2008-11-26T06:20:00.000
| 0 | 1 | 1 | 0 |
python,email,jython,attachment
| 320,285 | 4 | false | 0 | 0 |
Have you tried the get_payload( [i[, decode]]) method? Unlike walk it is not documented to recursively open attachments.
| 1 | 3 | 0 |
using jython
I have a situation where emails come in with different attachments. Certain file types I process others I ignore and dont write to file.
I am caught in a rather nasty situation, because sometimes people send an email as an attachment, and that attached email has legal attachments.
What I want to do is skip that attached email and all its attachments.
using python/jythons std email lib how can i do this?
to make it clearer
I need to parse an email (named ROOT email), I want to get the attachments from this email using jython.
Next certain attachments are supported ie .pdf .doc etc
now it just so happens that, the clients send an email (ROOT email) with another email message (CHILD email) as an attachment, and in CHILD email it has .pdf attachments and such like.
What I need is: to get rid of any CHILD emails attached to the ROOT email AND the CHILD emails attachments. What happens is I walk over the whole email and it just parses every attachment, BOTH ROOT attachments and CHILD attachments as if they were ROOT attachments.
I cannot have this. I am only interested in ROOT attachements that are legal ie .pdf .doc. xls .rtf .tif .tiff
That should do for now, I have to run to catch a bus!
thanks!
|
How do I skip processing the attachments of an email which is an attachment of a different email
| 0 | 0 | 0 | 978 |
320,232 |
2008-11-26T10:21:00.000
| 3 | 0 | 1 | 1 |
python,subprocess,kill,zombie-process
| 320,251 | 15 | false | 0 | 0 |
poll( )
Check if child process has terminated.
Returns returncode attribute.
| 1 | 77 | 0 |
Is there a way to ensure all created subprocess are dead at exit time of a Python program? By subprocess I mean those created with subprocess.Popen().
If not, should I iterate over all of the issuing kills and then kills -9? anything cleaner?
|
Ensuring subprocesses are dead on exiting Python program
| 0.039979 | 0 | 0 | 78,382 |
320,979 |
2008-11-26T14:58:00.000
| 1 | 0 | 0 | 0 |
php,python,plone
| 321,274 | 3 | false | 1 | 0 |
Well, use AJAX to call the PHP script (yes, you will need apache) and display the output. Adding a custom JS to plone is trivial and this abstract the technology issue.
Just be sure this is not a critical feature. Some users still deactivate JS and the web page should therefor degrade itself nicely.
| 1 | 2 | 0 |
I need to have the output of a PHP snippet in a Plone site. It was delivered to be a small library that has a display() function, in PHP, that outputs a line of text. But I need to put it in a Plone site. Do you have any recommendations?
I was thinking a long the lines of having a display.php that just runs display() and from the Plone template to download that URL and output the content. Do you think it might work? What methods of hitting a URL, retrieve the content and outputting can I use from inside a Plone template?
One important and critical constraint is that the output should be directly on the HTML and not an an iframe. This is a constraint coming from the outside, nothing technical.
|
How to include output of PHP script in Python driven Plone site?
| 0.066568 | 0 | 0 | 1,656 |
321,668 |
2008-11-26T18:21:00.000
| 1 | 0 | 1 | 0 |
python,image-processing
| 323,097 | 4 | false | 0 | 1 |
Install Python "for all users", not "just for me".
| 2 | 4 | 0 |
I'm trying to install the Python Imaging Library 1.1.6 for Python 2.6. After downloading the installation executable (Win XP), I receive the following error message:
"Application failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem"
Any thoughts on what I have done / not done? The application has not been installed, and I can't import the module through the IDLE session. Thoughts?
|
Application configuration incorrect with Python Imaging Library
| 0.049958 | 0 | 0 | 784 |
321,668 |
2008-11-26T18:21:00.000
| 0 | 0 | 1 | 0 |
python,image-processing
| 368,543 | 4 | false | 0 | 1 |
I got that same message recently to do with the wxPython library. It was because wxPython had been built using a later version of Visual C++ than I had on my PC. As atzz suggests, one solution is to install the appropriate redistributable package. Try a Google search for 'Microsoft Visual C++ 2008 Redistributable Package' and do the download. If that doesn't work, repeat for the 2005 version.
| 2 | 4 | 0 |
I'm trying to install the Python Imaging Library 1.1.6 for Python 2.6. After downloading the installation executable (Win XP), I receive the following error message:
"Application failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem"
Any thoughts on what I have done / not done? The application has not been installed, and I can't import the module through the IDLE session. Thoughts?
|
Application configuration incorrect with Python Imaging Library
| 0 | 0 | 0 | 784 |
321,795 |
2008-11-26T19:09:00.000
| 3 | 1 | 0 | 0 |
python,xml,elementtree
| 322,088 | 10 | false | 0 | 0 |
Why are you examining the XML data at all?
The way to test object serialization is to create an instance of the object, serialize it, deserialize it into a new object, and compare the two objects. When you make a change that breaks serialization or deserialization, this test will fail.
The only thing checking the XML data is going to find for you is if your serializer is emitting a superset of what the deserializer requires, and the deserializer silently ignores stuff it doesn't expect.
Of course, if something else is going to be consuming the serialized data, that's another matter. But in that case, you ought to be thinking about establishing a schema for the XML and validating it.
| 2 | 41 | 0 |
I have an object that can build itself from an XML string, and write itself out to an XML string. I'd like to write a unit test to test round tripping through XML, but I'm having trouble comparing the two XML versions. Whitespace and attribute order seem to be the issues. Any suggestions for how to do this? This is in Python, and I'm using ElementTree (not that that really matters here since I'm just dealing with XML in strings at this level).
|
Comparing XML in a unit test in Python
| 0.059928 | 0 | 1 | 17,177 |
321,795 |
2008-11-26T19:09:00.000
| 0 | 1 | 0 | 0 |
python,xml,elementtree
| 322,600 | 10 | false | 0 | 0 |
The Java component dbUnit does a lot of XML comparisons, so you might find it useful to look at their approach (especially to find any gotchas that they may have already addressed).
| 2 | 41 | 0 |
I have an object that can build itself from an XML string, and write itself out to an XML string. I'd like to write a unit test to test round tripping through XML, but I'm having trouble comparing the two XML versions. Whitespace and attribute order seem to be the issues. Any suggestions for how to do this? This is in Python, and I'm using ElementTree (not that that really matters here since I'm just dealing with XML in strings at this level).
|
Comparing XML in a unit test in Python
| 0 | 0 | 1 | 17,177 |
323,581 |
2008-11-27T12:10:00.000
| 1 | 0 | 1 | 0 |
python,ide
| 1,399,786 | 2 | false | 0 | 0 |
If you mean to the interactive console, use ctrl+alt+enter in the pydev editor (version 1.5).
That action does a number of things:
opens an interactive console view if it's not opened already
sends the selected text to the console
makes an execfile of the current editor (if no text is selected)
| 2 | 4 | 0 |
Question so easy that fitted in the title :)
Eclipse (pydev): Is it possible to assign a shortcut to send selection to the python console?
|
Eclipse (pydev): Is it possible to assign a shortcut to send selection to the python console?
| 0.099668 | 0 | 0 | 859 |
323,581 |
2008-11-27T12:10:00.000
| 1 | 0 | 1 | 0 |
python,ide
| 323,789 | 2 | false | 0 | 0 |
You can only assign shortcuts to "actions". Actions bound to buttons (for example, the toolbar) and menus. If you have a menu for this, you can bind a key to it. If not, then you will have to open an enhancement request in the pydev project.
| 2 | 4 | 0 |
Question so easy that fitted in the title :)
Eclipse (pydev): Is it possible to assign a shortcut to send selection to the python console?
|
Eclipse (pydev): Is it possible to assign a shortcut to send selection to the python console?
| 0.099668 | 0 | 0 | 859 |
323,866 |
2008-11-27T14:13:00.000
| 5 | 0 | 1 | 0 |
c#,java,.net,python
| 323,891 | 9 | true | 0 | 0 |
Create a hash table which stores function pointers (in C# that'd be delegates) for handling each of the parameters, keyed using the parameter text. Then you just go through the command line in a loop and make calls to delegates based on what comes out of hash table lookups.
| 3 | 4 | 0 |
I have a program that can have a lot of parameters (we have over +30 differents options).
Example:
myProgram.exe -t alpha 1 -prod 1 2 -sleep 200
This is 3 Commands (from command pattern object at the end) that each contain some parameters. Inside the code we parse all command (start with -) and get a list of string (split all space) for the parameters. So in fact, we have : string-->Collection of String parameters for each command.
For the moment, we use string comparison and we can get the whole thing works (instance the concrete command and return the ICommand interface). The problem is we require to do a lot of IF everytime to get the good command.
Do you have some pattern that can be used to extract all parameters from an EXE without using a lot of IF?
The code is in C# but I think the logic can be any other language too...
|
How to analyse .exe parameters inside the program?
| 1.2 | 0 | 0 | 1,655 |
323,866 |
2008-11-27T14:13:00.000
| 1 | 0 | 1 | 0 |
c#,java,.net,python
| 323,887 | 9 | false | 0 | 0 |
I'd be a little uncomfortable using a command line like that. First thing I'd say is "what does the first '1' mean, and why is it different to the second '1'?"
Any time I write a command line utility that accepts an argument, I consider how easy it would be for a user to learn all the options. In this case, it looks like a bit of a hard task, IMHO.
Maybe refactoring how the user passes the arguments would be a good idea. There's a reason why a lot of software takes key/value type parameters (e.g. myclient.exe -server=myServerName -config=debug) It takes a lot of load off the user, and also simplifies the argument parsing once it hits your code.
| 3 | 4 | 0 |
I have a program that can have a lot of parameters (we have over +30 differents options).
Example:
myProgram.exe -t alpha 1 -prod 1 2 -sleep 200
This is 3 Commands (from command pattern object at the end) that each contain some parameters. Inside the code we parse all command (start with -) and get a list of string (split all space) for the parameters. So in fact, we have : string-->Collection of String parameters for each command.
For the moment, we use string comparison and we can get the whole thing works (instance the concrete command and return the ICommand interface). The problem is we require to do a lot of IF everytime to get the good command.
Do you have some pattern that can be used to extract all parameters from an EXE without using a lot of IF?
The code is in C# but I think the logic can be any other language too...
|
How to analyse .exe parameters inside the program?
| 0.022219 | 0 | 0 | 1,655 |
323,866 |
2008-11-27T14:13:00.000
| 0 | 0 | 1 | 0 |
c#,java,.net,python
| 325,157 | 9 | false | 0 | 0 |
Commonly, you can replace large if/else or switch/case constructs with a Dictionary. Where the if-criteria is the key and the code to execute is the value.
For example, you could nave a Dictionary<string, ICommand> (or Dictionary<string, Type>), which you fill before you parse your command line.
When you iterate over the passed in command line options, you simply look them up in the dictionary and "invoke" on the value which is the matching command (object) to execute (or alternatively use Activate.CreateInstance(/*dictionary-value*/) if you stored the type instead of a specific object instance).
In C# 3.0 you could also something like Dictionary<string, System.Linq.Expressions.Expression<T>>, although this gets you pretty close to the actual if-statement - which is something you might want to have or not. YMMV.
Some libraries provide you with the mere parsing of the command line arguments (like traditionally getopt() et al did) or can provide the whole package, including the invokation of actions upon the presence of specific command line arguments.
| 3 | 4 | 0 |
I have a program that can have a lot of parameters (we have over +30 differents options).
Example:
myProgram.exe -t alpha 1 -prod 1 2 -sleep 200
This is 3 Commands (from command pattern object at the end) that each contain some parameters. Inside the code we parse all command (start with -) and get a list of string (split all space) for the parameters. So in fact, we have : string-->Collection of String parameters for each command.
For the moment, we use string comparison and we can get the whole thing works (instance the concrete command and return the ICommand interface). The problem is we require to do a lot of IF everytime to get the good command.
Do you have some pattern that can be used to extract all parameters from an EXE without using a lot of IF?
The code is in C# but I think the logic can be any other language too...
|
How to analyse .exe parameters inside the program?
| 0 | 0 | 0 | 1,655 |
323,972 |
2008-11-27T14:55:00.000
| -1 | 0 | 1 | 0 |
python,multithreading,kill,terminate
| 24,353,228 | 30 | false | 0 | 0 |
If you really need the ability to kill a sub-task, use an alternate implementation. multiprocessing and gevent both support indiscriminately killing a "thread".
Python's threading does not support cancellation. Do not even try. Your code is very likely to deadlock, corrupt or leak memory, or have other unintended "interesting" hard-to-debug effects which happen rarely and nondeterministically.
| 4 | 914 | 0 |
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
|
Is there any way to kill a Thread?
| -0.006667 | 0 | 0 | 1,043,639 |
323,972 |
2008-11-27T14:55:00.000
| 134 | 0 | 1 | 0 |
python,multithreading,kill,terminate
| 323,993 | 30 | false | 0 | 0 |
There is no official API to do that, no.
You need to use platform API to kill the thread, e.g. pthread_kill, or TerminateThread. You can access such API e.g. through pythonwin, or through ctypes.
Notice that this is inherently unsafe. It will likely lead to uncollectable garbage (from local variables of the stack frames that become garbage), and may lead to deadlocks, if the thread being killed has the GIL at the point when it is killed.
| 4 | 914 | 0 |
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
|
Is there any way to kill a Thread?
| 1 | 0 | 0 | 1,043,639 |
323,972 |
2008-11-27T14:55:00.000
| 33 | 0 | 1 | 0 |
python,multithreading,kill,terminate
| 323,981 | 30 | false | 0 | 0 |
You should never forcibly kill a thread without cooperating with it.
Killing a thread removes any guarantees that try/finally blocks set up so you might leave locks locked, files open, etc.
The only time you can argue that forcibly killing threads is a good idea is to kill a program fast, but never single threads.
| 4 | 914 | 0 |
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
|
Is there any way to kill a Thread?
| 1 | 0 | 0 | 1,043,639 |
323,972 |
2008-11-27T14:55:00.000
| 11 | 0 | 1 | 0 |
python,multithreading,kill,terminate
| 324,002 | 30 | false | 0 | 0 |
It is better if you don't kill a thread.
A way could be to introduce a "try" block into the thread's cycle and to throw an exception when you want to stop the thread (for example a break/return/... that stops your for/while/...).
I've used this on my app and it works...
| 4 | 914 | 0 |
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
|
Is there any way to kill a Thread?
| 1 | 0 | 0 | 1,043,639 |
325,165 |
2008-11-28T06:40:00.000
| 1 | 1 | 1 | 0 |
python
| 325,180 | 9 | false | 0 | 0 |
what language a block of code is written in
What are your alternatives, among what languages? There is no way to determine this universally. But if you narrow your focus there is probably a tool somewhere
| 2 | 22 | 0 |
Writing a python script and it needs to find out what language a block of code is written in. I could easily write this myself, but I'd like to know if a solution already exists.
Pygments is insufficient and unreliable.
|
Is there a library that will detect the source code language of a block of code?
| 0.022219 | 0 | 0 | 4,415 |
325,165 |
2008-11-28T06:40:00.000
| 0 | 1 | 1 | 0 |
python
| 346,832 | 9 | false | 0 | 0 |
As other have said Pygments will be your best bet.
| 2 | 22 | 0 |
Writing a python script and it needs to find out what language a block of code is written in. I could easily write this myself, but I'd like to know if a solution already exists.
Pygments is insufficient and unreliable.
|
Is there a library that will detect the source code language of a block of code?
| 0 | 0 | 0 | 4,415 |
327,002 |
2008-11-29T01:24:00.000
| 9 | 1 | 1 | 0 |
python,performance
| 327,009 | 15 | false | 0 | 0 |
How many square roots are you really performing? Are you trying to write some 3D graphics engine in Python? If not, then why go with code which is cryptic over code that is easy to read? The time difference is would be less than anybody could notice in just about any application I could forsee. I really don't mean to put down your question, but it seems that you're going a little too far with premature optimization.
| 4 | 236 | 0 |
I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?
UPDATE
This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code works?
I sent Guido van Rossum an email cause I really wanted to know the differences in these methods.
My email:
There are at least 3 ways to do a square root in Python: math.sqrt, the
'**' operator and pow(x,.5). I'm just curious as to the differences in
the implementation of each of these. When it comes to efficiency which
is better?
His response:
pow and ** are equivalent; math.sqrt doesn't work for complex numbers,
and links to the C sqrt() function. As to which one is
faster, I have no idea...
|
Which is faster in Python: x**.5 or math.sqrt(x)?
| 1 | 0 | 0 | 100,568 |
327,002 |
2008-11-29T01:24:00.000
| 4 | 1 | 1 | 0 |
python,performance
| 327,063 | 15 | false | 0 | 0 |
using Claudiu's code, on my machine even with "from math import sqrt" x**.5 is faster but using psyco.full() sqrt(x) becomes much faster, at least by 200%
| 4 | 236 | 0 |
I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?
UPDATE
This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code works?
I sent Guido van Rossum an email cause I really wanted to know the differences in these methods.
My email:
There are at least 3 ways to do a square root in Python: math.sqrt, the
'**' operator and pow(x,.5). I'm just curious as to the differences in
the implementation of each of these. When it comes to efficiency which
is better?
His response:
pow and ** are equivalent; math.sqrt doesn't work for complex numbers,
and links to the C sqrt() function. As to which one is
faster, I have no idea...
|
Which is faster in Python: x**.5 or math.sqrt(x)?
| 0.053283 | 0 | 0 | 100,568 |
327,002 |
2008-11-29T01:24:00.000
| 3 | 1 | 1 | 0 |
python,performance
| 327,005 | 15 | false | 0 | 0 |
Most likely math.sqrt(x), because it's optimized for square rooting.
Benchmarks will provide you the answer you are looking for.
| 4 | 236 | 0 |
I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?
UPDATE
This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code works?
I sent Guido van Rossum an email cause I really wanted to know the differences in these methods.
My email:
There are at least 3 ways to do a square root in Python: math.sqrt, the
'**' operator and pow(x,.5). I'm just curious as to the differences in
the implementation of each of these. When it comes to efficiency which
is better?
His response:
pow and ** are equivalent; math.sqrt doesn't work for complex numbers,
and links to the C sqrt() function. As to which one is
faster, I have no idea...
|
Which is faster in Python: x**.5 or math.sqrt(x)?
| 0.039979 | 0 | 0 | 100,568 |
327,002 |
2008-11-29T01:24:00.000
| -4 | 1 | 1 | 0 |
python,performance
| 29,231,648 | 15 | false | 0 | 0 |
What would be even faster is if you went into math.py and copied the function "sqrt" into your program. It takes time for your program to find math.py, then open it, find the function you are looking for, and then bring that back to your program. If that function is faster even with the "lookup" steps, then the function itself has to be awfully fast. Probably will cut your time in half. IN summary:
Go to math.py
Find the function "sqrt"
Copy it
Paste function into your program as the sqrt finder.
Time it.
| 4 | 236 | 0 |
I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?
UPDATE
This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code works?
I sent Guido van Rossum an email cause I really wanted to know the differences in these methods.
My email:
There are at least 3 ways to do a square root in Python: math.sqrt, the
'**' operator and pow(x,.5). I'm just curious as to the differences in
the implementation of each of these. When it comes to efficiency which
is better?
His response:
pow and ** are equivalent; math.sqrt doesn't work for complex numbers,
and links to the C sqrt() function. As to which one is
faster, I have no idea...
|
Which is faster in Python: x**.5 or math.sqrt(x)?
| -1 | 0 | 0 | 100,568 |
327,026 |
2008-11-29T01:46:00.000
| 5 | 0 | 0 | 0 |
python,linux,curses,bold
| 53,016,371 | 2 | false | 0 | 1 |
I tried this: screen.addstr(text, curses.color_pair(1) | curses.A_BOLD) and it worked!
So just add curses. and it should do the trick.
Of course at the beginning use: import curses
| 1 | 6 | 0 |
I use something like this:
screen.addstr(text, color_pair(1) | A_BOLD), but it doesn't seem to work..
However, A_REVERSE and all others attribute does work!
In fact, I'm trying to print something in white, but the COLOR_WHITE prints it gray.. and after a while of searching, it seems that printing it gray + BOLD makes it!
Any helps would be greatly appreciated.
|
Attribute BOLD doesn't seem to work in my curses
| 0.462117 | 0 | 0 | 6,287 |
327,101 |
2008-11-29T03:11:00.000
| 11 | 0 | 0 | 0 |
python,ruby-on-rails,web2py
| 327,684 | 3 | false | 1 | 0 |
c'mon guys... your only argument is "Technical differences are rather irrelevant." and "it don't matter what web framework you use"? I disagree. The size of the users base has more to do with marketing and how long a framework has been around. By that argument ASP and PHP are better than Rails.
Has anybody here used both Rails and web2py?
web2py runs on webfaction and any hosting provider that supports mod_proxy or mod_wsgi or mod_fcgi, and runs on Google App Engine (rails does not). There is also a dedicated web2py hosting provider (star-nix.com).
| 3 | 13 | 0 |
web2py to is a Python framework but shares the "convention over configuration" design that Ruby on Rails has. On the plus side it packages a lot more functionality with its s standard distribution and we claim it is faster and easier to use.
Has any Rails user tried it? What is your impression?
No rants please. Just technical comments.
|
@Rails users: have you tried web2py? Pros? Cons?
| 1 | 0 | 0 | 2,962 |
327,101 |
2008-11-29T03:11:00.000
| 1 | 0 | 0 | 0 |
python,ruby-on-rails,web2py
| 1,250,930 | 3 | false | 1 | 0 |
I found web2py much easier to learn... there are fewer scripts to run and abstractions. On the other hand, web2py's database layer isn't a real ORM... it's almost like writing raw SQL. Simple things end up taking many lines of code, just like SQL.
| 3 | 13 | 0 |
web2py to is a Python framework but shares the "convention over configuration" design that Ruby on Rails has. On the plus side it packages a lot more functionality with its s standard distribution and we claim it is faster and easier to use.
Has any Rails user tried it? What is your impression?
No rants please. Just technical comments.
|
@Rails users: have you tried web2py? Pros? Cons?
| 0.066568 | 0 | 0 | 2,962 |
327,101 |
2008-11-29T03:11:00.000
| 0 | 0 | 0 | 0 |
python,ruby-on-rails,web2py
| 327,519 | 3 | false | 1 | 0 |
I would say the biggest "con" of using webpy over Rails is that there are not a lot of Rails-specific hosting services around, and the huge community based around it (there are Rails plugins and tools for.. everything). The same cannot be said for web2py.
It depends what you want to do with it - if it's something to write your personal site with, and you already have a server to host it on, use whatever you prefer. If it's something to distribute for others to run, Rails has more options for hosting, and a bigger community, so it may be a better choice.
Technical differences are rather irrelevant. Every framework can basically do the same (generate web-pages). What is important is community, ease of use, useful feature-sets, ability to host it and so on - and those are all really subjective.
I still use PHP quite often, not because "it's better", but because I can host it on a huge majority of web-hosts. I also use Rails because as it has a good, and very active community. The actually technicalities of the framework wasn't ever a consideration, really..
I could probably put together a list of why web2py is "better"/"worse" than Rails - Rails may be 0.04sec/request slower at generating templates containing loops, or web2py may have a good DB model generator, or some other technical reason - but those may not be relevant to you at all
| 3 | 13 | 0 |
web2py to is a Python framework but shares the "convention over configuration" design that Ruby on Rails has. On the plus side it packages a lot more functionality with its s standard distribution and we claim it is faster and easier to use.
Has any Rails user tried it? What is your impression?
No rants please. Just technical comments.
|
@Rails users: have you tried web2py? Pros? Cons?
| 0 | 0 | 0 | 2,962 |
327,142 |
2008-11-29T04:01:00.000
| 0 | 0 | 0 | 0 |
python,django,admin
| 327,296 | 5 | false | 1 | 0 |
The session information is stored in the database, so if you're sharing the database with both running instances, logging off one location will log you off both. If your circumstance requires you to share the database, the easiest workaround is probably to create a second user account with admin privileges.
| 4 | 3 | 0 |
I have two Django projects and applications running on the same Apache installation. Both projects and both applications have the same name, for example myproject.myapplication. They are each in separately named directories so it looks like .../dir1/myproject/myapplication and .../dir2/myproject/myapplication.
Everything about the actual public facing applications works fine. When I log into either of the admin sites it seems ok, but if I switch and do any work on the opposite admin site I get logged out of the first one. In short I can't be logged into both admin sites at once. Any help would be appreciated.
|
Multiple Django Admin Sites on one Apache... When I log into one I get logged out of the other
| 0 | 0 | 0 | 1,679 |
327,142 |
2008-11-29T04:01:00.000
| 1 | 0 | 0 | 0 |
python,django,admin
| 1,007,356 | 5 | false | 1 | 0 |
I ran into a similar issue with a live & staging site hosted on the same Apache server (on CentOS). I added unique SESSION_COOKIE_NAME values to each site's settings (in local_settings.py, create one if you don't have one and import it in your settings.py), set the SESSION_COOKIE_DOMAIN for the live site and set SESSION_COOKIE_DOMAIN = None for staging. I also ran "python manage.py cleanup" to (hopefully) clean any conflicted information out of the database.
| 4 | 3 | 0 |
I have two Django projects and applications running on the same Apache installation. Both projects and both applications have the same name, for example myproject.myapplication. They are each in separately named directories so it looks like .../dir1/myproject/myapplication and .../dir2/myproject/myapplication.
Everything about the actual public facing applications works fine. When I log into either of the admin sites it seems ok, but if I switch and do any work on the opposite admin site I get logged out of the first one. In short I can't be logged into both admin sites at once. Any help would be appreciated.
|
Multiple Django Admin Sites on one Apache... When I log into one I get logged out of the other
| 0.039979 | 0 | 0 | 1,679 |
327,142 |
2008-11-29T04:01:00.000
| 0 | 0 | 0 | 0 |
python,django,admin
| 327,398 | 5 | false | 1 | 0 |
Let me guess, is this running on your localhost? and you have each site assigned to a different port? i.e. localhost:8000, localhost:8001 ..?
I've had the same problem! (although I wasn't running Apache per se)
When you login to the admin site, you get a cookie in your browser that's associated with the domain "localhost", the cookie stores a pointer of some sort to a session stored in the database on the server.
When you visit the other site, the server tries to interpret the cookie, but fails. I'm guessing it deletes the cookie because it's "garbage".
What you can do in this case, is change your domain
use localhost:8000 for the first site, and 127.0.0.1:8001 for the second site. this way the second site doesn't attempt to read the cookie that was set by the first site
I also think you can edit your HOSTS file to add more aliases to 127.0.0.1 if you need to. (but I haven't tried this)
| 4 | 3 | 0 |
I have two Django projects and applications running on the same Apache installation. Both projects and both applications have the same name, for example myproject.myapplication. They are each in separately named directories so it looks like .../dir1/myproject/myapplication and .../dir2/myproject/myapplication.
Everything about the actual public facing applications works fine. When I log into either of the admin sites it seems ok, but if I switch and do any work on the opposite admin site I get logged out of the first one. In short I can't be logged into both admin sites at once. Any help would be appreciated.
|
Multiple Django Admin Sites on one Apache... When I log into one I get logged out of the other
| 0 | 0 | 0 | 1,679 |
327,142 |
2008-11-29T04:01:00.000
| 0 | 0 | 0 | 0 |
python,django,admin
| 327,237 | 5 | false | 1 | 0 |
Well, if they have the same project and application names, then the databases and tables will be the same. Your django_session table which holds the session information is the same for both sites. You have to use different project names that will go in different MySQL (or whatever) databases.
| 4 | 3 | 0 |
I have two Django projects and applications running on the same Apache installation. Both projects and both applications have the same name, for example myproject.myapplication. They are each in separately named directories so it looks like .../dir1/myproject/myapplication and .../dir2/myproject/myapplication.
Everything about the actual public facing applications works fine. When I log into either of the admin sites it seems ok, but if I switch and do any work on the opposite admin site I get logged out of the first one. In short I can't be logged into both admin sites at once. Any help would be appreciated.
|
Multiple Django Admin Sites on one Apache... When I log into one I get logged out of the other
| 0 | 0 | 0 | 1,679 |
327,597 |
2008-11-29T15:01:00.000
| 0 | 0 | 1 | 0 |
python
| 327,735 | 6 | false | 0 | 1 |
To your first question I agree with Ali A.
To your second question :
import sys
sys.exit(1)
| 1 | 3 | 0 |
I'm giving my first steps on Python. I saw that we don't have switch case statement,
so I would you guys implement a text Menu in python?
Thanks
|
Suggestion to implement a text Menu without switch case
| 0 | 0 | 0 | 5,723 |
327,985 |
2008-11-29T20:41:00.000
| 0 | 0 | 1 | 0 |
python,file
| 327,992 | 4 | false | 0 | 0 |
Don't work with files directly, make a data structure that fits your needs in form of a class and make read from/write to file methods.
| 1 | 9 | 0 |
The last line of my file is:
29-dez,40,
How can I modify that line so that it reads:
29-Dez,40,90,100,50
Note: I don't want to write a new line. I want to take the same line and put new values after 29-Dez,40,
I'm new at python. I'm having a lot of trouble manipulating files and for me every example I look at seems difficult.
|
How do I modify the last line of a file?
| 0 | 0 | 0 | 11,474 |
328,041 |
2008-11-29T21:34:00.000
| 3 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,062 | 13 | false | 0 | 0 |
If Low memory and low startup time are truly important you might want to consider doing the work to keep the C code cross platform, however I have found this is rarely necessary.
Personally I would use Ruby or Python for this type of job, they both make it very easy to make clear understandable code that others can maintain (or you can maintain after not looking at it for 6 months). If you have the control to do so I would also suggest getting the latest version of the interpreter, as both Ruby and Python have made notable improvements around performance recently.
It is a bit of a personal thing. Programming Ruby makes me happy, C code does not (nor bash scripting for anything non-trivial).
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 0.046121 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 0 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,075 | 13 | false | 0 | 0 |
I agree with others in that you should probably try to make this a more portable C app instead of porting it over to something else since any scripting language is going to introduce significant overhead from a startup perspective, have a much larger memory footprint, and will probably be much slower.
In my experience, Python is the most efficient of the three, followed by Perl and then Ruby with the difference between Perl and Ruby being particularly large in certain areas. If you really want to try porting this to a scripting language, I would put together a prototype in the language you are most comfortable with and see if it comes close to your requirements. If you don't have a preference, start with Python as it is easy to learn and use and if it is too slow with Python, Perl and Ruby probably won't be able to do any better.
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 0 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 5 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,054 | 13 | false | 0 | 0 |
When written properly, C should be platform independant and would only need a recompile for those different platforms. You might have to jump through some #ifdef hoops for the headers (not all systems use the same headers), but most normal (non-win32 API) calls are very portable.
For web access (which I presume you need as you mention bash+curl), you could take a look at libcurl, it's available for all the platforms you mentioned, and shouldn't be that hard to work with.
With execution time and memory cost in mind, I doubt you could go any faster than properly written C with any scripting language as you would lose at least some time on interpreting the script...
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 0.076772 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 4 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,120 | 13 | false | 0 | 0 |
I concur with Lua: it is super-portable, it has XML libraries, either native or by binding C libraries like Expat, it has a good socket library (LuaSocket) plus, for complex stuff, some cURL bindings, and is well known for being very lightweight (often embedded in low memory devices), very fast (one of the fastest scripting languages), and powerful. And very easy to code!
It is coded in pure Ansi C, and lot of people claim it has one of the best C biding API (calling C routines from Lua, calling Lua code from C...).
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 0.061461 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 9 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,065 | 13 | true | 0 | 0 |
Because of your requirement for fast startup time and a calling frequency greater than 1Hz I'd recommend either staying with C and figuring out how to make it portable (not always as easy as a few ifdefs) or exploring the possibility of turning it into a service daemon that is always running. Of course this depends on how
Python can have lower startup times if you compile the module and run the .pyc file, but it is still generally considered slow. Perl, in my experience, in the fastest of the scripting languages so you might have good luck with a perl daemon.
You could also look at cross platform frameworks like gtk, wxWidgets and Qt. While they are targeted at GUIs they do have low level cross platform data types and network libraries that could make the job of using a fast C based application easier.
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 1.2 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 23 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,045 | 13 | false | 0 | 0 |
Lua is a scripting language that meets your criteria. It's certainly the fastest and lowest memory scripting language available.
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 1 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 0 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,519 | 13 | false | 0 | 0 |
Port your app to Ruby. If your app is too slow, profile it and rewrite the those parts in C.
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 0 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 6 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,129 | 13 | false | 0 | 0 |
"called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important."
This doesn't sound like a script to me at all.
This sounds like a server handling requests that arrive from every minute to several times a second.
If it's a server, handling requests, start-up time doesn't mean as much as responsiveness. In which case, Python might work out well, and still keep performance up.
Rather than restarting, you're just processing another request. You get to keep as much state as you need to optimize performance.
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 1 | 0 | 0 | 8,004 |
328,041 |
2008-11-29T21:34:00.000
| 0 | 1 | 0 | 1 |
python,ruby,perl,bash,scripting-language
| 328,132 | 13 | false | 0 | 0 |
Can you instead have it be a long-running process and answer http or rpc requests?
This would satisfy the latency requirements in almost any scenario, but I don't know if that would break your memory footprint constraints.
| 9 | 10 | 0 |
I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.
The existing C application works fine but I want to have a single script I can maintain for all platforms. At the same time, I do not want to lose a lot of performance but am willing to lose some.
Startup cost of the script is very important. This script can be called anywhere from every minute to many times per second. As a consequence, keeping it's memory and startup time low are important.
So basically I'm looking for the best scripting languages that is:
Cross platform.
Capable of XML parsing and HTTP Posts.
Low memory and low startup time.
Possible choices include but are not limited to: bash/ksh + curl, Perl, Python and Ruby. What would you recommend for this type of a scenario?
|
Scripting language choice for initial performance
| 0 | 0 | 0 | 8,004 |
328,107 |
2008-11-29T22:37:00.000
| 9 | 0 | 1 | 0 |
python,math,geometry
| 328,142 | 21 | false | 0 | 0 |
Here's another approach:
Lets assume the two points be A (x1,y1) and B (x2,y2)
The equation of the line passing through those points is (x-x1)/(y-y1)=(x2-x1)/(y2-y1) .. (just making equating the slopes)
Point C (x3,y3) will lie between A & B if:
x3,y3 satisfies the above equation.
x3 lies between x1 & x2 and y3 lies between y1 & y2 (trivial check)
| 2 | 111 | 0 |
Let's say you have a two dimensional plane with 2 points (called a and b) on it represented by an x integer and a y integer for each point.
How can you determine if another point c is on the line segment defined by a and b?
I use python most, but examples in any language would be helpful.
|
How can you determine a point is between two other points on a line segment?
| 1 | 0 | 0 | 146,297 |
328,107 |
2008-11-29T22:37:00.000
| 0 | 0 | 1 | 0 |
python,math,geometry
| 329,347 | 21 | false | 0 | 0 |
how about just ensuring that the slope is the same and the point is between the others?
given points (x1, y1) and (x2, y2) ( with x2 > x1)
and candidate point (a,b)
if (b-y1) / (a-x1) = (y2-y2) / (x2-x1) And x1 < a < x2
Then (a,b) must be on line between (x1,y1) and (x2, y2)
| 2 | 111 | 0 |
Let's say you have a two dimensional plane with 2 points (called a and b) on it represented by an x integer and a y integer for each point.
How can you determine if another point c is on the line segment defined by a and b?
I use python most, but examples in any language would be helpful.
|
How can you determine a point is between two other points on a line segment?
| 0 | 0 | 0 | 146,297 |
328,577 |
2008-11-30T07:14:00.000
| 4 | 1 | 1 | 0 |
c++,python
| 328,599 | 8 | false | 0 | 1 |
I learned a lot about Python by reading the source of the standard library that ships with Python. I seem to remember having a few "a-ha!" moments when reading urllib2.py in particular.
| 3 | 56 | 0 |
I'm a long time C++/Java developer trying to get into Python and am looking for the stereotypical "Python for C++ Developers" article, but coming up blank. I've seen these sort of things for C#, Java, etc, and they're incredibly useful for getting up to speed on language features and noteworthy differences. Anyone have any references?
As a secondary bonus question, what open source Python program would you suggest looking at for clean design, commenting, and use of the language as a point of reference for study?
Thanks in advance.
|
Python for C++ Developers
| 0.099668 | 0 | 0 | 43,679 |
328,577 |
2008-11-30T07:14:00.000
| 0 | 1 | 1 | 0 |
c++,python
| 328,598 | 8 | false | 0 | 1 |
For the best examples of code of a language, the language's standard library is often a good place to look. Pick a recent piece, though - old parts are probably written for older versions and also sometimes were written before the library became big enough to warrant big standards - like PHP and Erlang's libraries, which have internal inconsistency.
For Python in particular, Python 3000 is cleaning up the library a lot, and so is probably a great source of good Python code (though it is written for a future Python version).
| 3 | 56 | 0 |
I'm a long time C++/Java developer trying to get into Python and am looking for the stereotypical "Python for C++ Developers" article, but coming up blank. I've seen these sort of things for C#, Java, etc, and they're incredibly useful for getting up to speed on language features and noteworthy differences. Anyone have any references?
As a secondary bonus question, what open source Python program would you suggest looking at for clean design, commenting, and use of the language as a point of reference for study?
Thanks in advance.
|
Python for C++ Developers
| 0 | 0 | 0 | 43,679 |
328,577 |
2008-11-30T07:14:00.000
| 1 | 1 | 1 | 0 |
c++,python
| 328,689 | 8 | false | 0 | 1 |
C# and Java are seen as cleaner replacements for C++ in many application areas so there is often a "migration" from one to the other - which is why there are books available.
Python and C++ are very different beasts, and although they are both considered general purpose programming languages they are targetted towards different ends of the programming spectrum.
Don't try to write C++ in Python; in fact, try to forget C++ when writing Python.
I found it far better to learn the common Python paradigms and techniques and apply them to my C++ programs than the other way around.
| 3 | 56 | 0 |
I'm a long time C++/Java developer trying to get into Python and am looking for the stereotypical "Python for C++ Developers" article, but coming up blank. I've seen these sort of things for C#, Java, etc, and they're incredibly useful for getting up to speed on language features and noteworthy differences. Anyone have any references?
As a secondary bonus question, what open source Python program would you suggest looking at for clean design, commenting, and use of the language as a point of reference for study?
Thanks in advance.
|
Python for C++ Developers
| 0.024995 | 0 | 0 | 43,679 |
331,377 |
2008-12-01T16:40:00.000
| 2 | 0 | 1 | 1 |
python,linux,deployment
| 331,703 | 4 | false | 0 | 0 |
But if you make a deb with the correct dependencies listed the installer will download them for the user. That's the best way, as it's non redundant.
Maybe you could make a tar or zip with your deb and all the third-party deb's and an install script that just install all the debs in the correct order. This way, if the user already has some package it wouldn't be installed again.
| 1 | 4 | 0 |
How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible and also not to conflict with different lib/version that is already on my system.
L.E.: Sorry i forgot to specify. I will be doing this on linux. And I'm not referring in making my app a installable file like deb/rpm, etc but how to organize my files so like for example I'll be using cherrypy and sqlalchemy I'll ship those with my app and not put the user through the pain of installing all the dependencies by himself.
|
How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible
| 0.099668 | 0 | 0 | 505 |
331,855 |
2008-12-01T19:10:00.000
| 1 | 1 | 0 | 0 |
python,http,http-headers
| 331,871 | 2 | false | 0 | 0 |
When you open the URL with urllib2, and you're redirected, you get a status 30x for redirection. Check the info to see the location to which you're redirected. You don't need to read the page to read the info() that's part of the response.
| 1 | 5 | 0 |
I need to check whether a page is being redirected or not without actually downloading the content. I just need the final URL. What's the best way of doing this is Python?
Thanks!
|
How to determine if a page is being redirected
| 0.099668 | 0 | 1 | 3,318 |
331,918 |
2008-12-01T19:31:00.000
| 4 | 0 | 1 | 0 |
python,pdf,imagemagick,jpeg,python-imaging-library
| 657,704 | 5 | false | 1 | 0 |
You can't avoid the Ghostscript dependency. Even Imagemagick relies on Ghostscript for its PDF reading functions. The reason for this is the complexity of the PDF format: a PDF doesn't just contain bitmap information, but mostly vector shapes, transparencies etc.
Furthermore it is quite complex to figure out which of these objects appear on which page.
So the correct rendering of a PDF Page is clearly out of scope for a pure Python library.
The good news is that Ghostscript is pre-installed on many windows and Linux systems, because it is also needed by all those PDF Printers (except Adobe Acrobat).
| 1 | 50 | 0 |
I'm attempting to use Python to convert a multi-page PDF into a series of JPEGs. I can split the PDF up into individual pages easily enough with available tools, but I haven't been able to find anything that can covert PDFs to images.
PIL does not work, as it can't read PDFs. The two options I've found are using either GhostScript or ImageMagick through the shell. This is not a viable option for me, since this program needs to be cross-platform, and I can't be sure either of those programs will be available on the machines it will be installed and used on.
Are there any Python libraries out there that can do this?
|
Converting a PDF to a series of images with Python
| 0.158649 | 0 | 0 | 44,444 |
332,255 |
2008-12-01T21:17:00.000
| 6 | 0 | 1 | 0 |
python
| 332,575 | 4 | false | 0 | 0 |
Subclassing object yields a new-style class. Two well known advantages of new-style classes are:
Metaclasses (like class factories, but works transparently)
Properties (getters & setters...)
| 1 | 72 | 0 |
I know class foo(object) is an old school way of defining a class. But I would like to understand in more detail the difference between these two.
|
Difference between class foo and class foo(object) in Python
| 1 | 0 | 0 | 33,698 |
333,995 |
2008-12-02T13:58:00.000
| 28 | 0 | 1 | 0 |
python,debugging
| 334,090 | 10 | false | 0 | 0 |
Python debuggers (as well as profilers and coverage tools) use the sys.settrace function (in the sys module) to register a callback that gets called when interesting events happen.
If you're using Python 2.6, you can call sys.gettrace() to get the current trace callback function. If it's not None then you can assume you should be passing debug parameters to the JVM.
It's not clear how you could do this pre 2.6.
| 1 | 35 | 0 |
Is there a simple way to detect, within Python code, that this code is being executed through the Python debugger?
I have a small Python application that uses Java code (thanks to JPype). When I'm debugging the Python part, I'd like the embedded JVM to be passed debug options too.
|
How to detect that Python code is being executed through the debugger?
| 1 | 0 | 0 | 9,637 |
334,765 |
2008-12-02T17:30:00.000
| 1 | 0 | 0 | 0 |
python,symbian,s60,pys60
| 337,308 | 2 | true | 0 | 1 |
Linux is not officially supported for Series60 development yet. You will save yourself a lot of headache using Windows, weirdly enough.
As far as Python is oncerned, I think the developed application is packaged into a .sis file but still requires the PyS60 interpreter to run once installed.
| 1 | 9 | 0 |
I am currently looking at developing a mobile apps for the S60 platform and is specifically looking at PyS60. It seems to suggest that the it can be compiled into native .sis files without the need for an embedded python interpreter. Reading through the documentations I could not find any statements where this is explicitly mentioned. While I am right now downloading the SDKs, Emulators, and the whole bunch of tool chains needed to test the development out on Linux, I thought I would ask here a bit while I am doing that.
|
Does PyS60 produce sis files that are native?
| 1.2 | 0 | 0 | 1,161 |
335,078 |
2008-12-02T19:09:00.000
| 5 | 0 | 1 | 0 |
python
| 335,106 | 4 | false | 0 | 0 |
There is no other way to compute the size than recursively invoking stat. This is independent of Python; the operating system just provides no other way.
The algorithm doesn't have to be recursive; you can use os.walk.
There might be two exceptions to make it more efficient:
If all the files you want to measure fill a partition, and the partition has no other files, then you can look at the disk usage of the partition.
If you can continuously monitor all files, or are responsible for creating all the files yourself, you can generate an incremental disk usage.
| 2 | 6 | 0 |
If there will be a small number of files it should be easy with a recursive function to pass through all the files and add the size but what if there are lots of files, and by lots i really mean lots of files.
|
What's the best way to get the size of a folder and all the files inside from python?
| 0.244919 | 0 | 0 | 3,802 |
335,078 |
2008-12-02T19:09:00.000
| 0 | 0 | 1 | 0 |
python
| 9,439,237 | 4 | false | 0 | 0 |
If you are on a posix system that provides du, you should be able to use pexpect.run or subprocess to execute du <path to folder> to get the size of the folder and subfiles. Keep in mind it will output a string with each file listed and each folder totaled. (Look at the du manpage to see what you can do to limit that).
| 2 | 6 | 0 |
If there will be a small number of files it should be easy with a recursive function to pass through all the files and add the size but what if there are lots of files, and by lots i really mean lots of files.
|
What's the best way to get the size of a folder and all the files inside from python?
| 0 | 0 | 0 | 3,802 |
336,753 |
2008-12-03T10:29:00.000
| 1 | 0 | 0 | 0 |
python,django,forms
| 337,753 | 2 | true | 1 | 0 |
There's a lot that you can do, but you'd need to be more specific about what you mean by "integrate a formwizard into the admin app" and "trigger several forms within the admin app."
The admin app at its core is basically just a wrapper around a bunch of stock ModelForms, so if you just build a formwizard using ModelForms and slap the admin styling on it, you may be 80% of the way there.
| 1 | 3 | 0 |
I have a series of forms that I need a user to complete in sequence, which is perfect for the formwizard app. However, I've some need of the admin application also and would like to set the whole thing up to trigger several forms within the admin app.
Is it possible/easy to integrate a 'formwizard' into the admin application?
If not, is extending the admin template a viable option and hooking the rest up manually? Opinions?
Update:
Some clarity in my 'problem'.
I wanted to use the admin app as I was thinking I only needed basic modelforms - one perhaps split across many forms, which would have been the role of formwizard.
What I have:
Form 1: 10 yes/no questions (each yes corresponds to a new form that needs to be filled out)
if yes is ticked, the corresponding forms are put into a formwizard and displayed for the user to complete.
However the suggested option (modelforms + styling) would take care of the majority of my concerns I guess - and is the seemingly simpler solution.
|
Django FormWizard and Admin application
| 1.2 | 0 | 0 | 1,539 |
336,963 |
2008-12-03T12:36:00.000
| 0 | 0 | 1 | 0 |
python,optparse
| 3,882,232 | 5 | false | 0 | 0 |
metavar is a variable used for print in the screen after option. Usually used for suggestion input after option are FILE or INT or STRING to user. Without metavar, optparse will print dest value after option you've been added.
| 1 | 26 | 0 |
I am not sure what optparse's metavar parameter is used for. I see it is used all around, but I can't see its use.
Can someone make it clear to me? Thanks.
|
Python optparse metavar
| 0 | 0 | 0 | 12,451 |
337,870 |
2008-12-03T16:54:00.000
| 7 | 0 | 1 | 1 |
python,multithreading,subprocess
| 337,990 | 3 | true | 0 | 0 |
sys.stdin and sys.stdout handles are invalid because pythonw does not provide console support as it runs as a deamon, so default arguments of subprocess.call() are failing.
Deamon programs close stdin/stdout/stderr purposedly and use logging instead, so that you have to manage this yourself: I would suggest to use subprocess.PIPE.
If you really don't care about what the sub process says for errors and all, you could use os.devnull (I'm not really sure how portable it is?) but I wouldn't recommend that.
| 2 | 5 | 0 |
I have some Python code that works correctly when I use python.exe to run it, but fails if I use pythonw.exe.
def runStuff(commandLine):
outputFileName = 'somefile.txt'
outputFile = open(outputFileName, "w")
try:
result = subprocess.call(commandLine, shell=True, stdout=outputFile)
except:
print 'Exception thrown:', str(sys.exc_info()[1])
myThread = threading.Thread(None, target=runStuff, commandLine=['whatever...'])
myThread.start()
The message I get is:
Exception thrown: [Error 6] The handle is invalid
However, if I don't specify the 'stdout' parameter, subprocess.call() starts okay.
I can see that pythonw.exe might be redirecting output itself, but I can't see why I'm blocked from specifying stdout for a new thread.
|
Python subprocess.call() fails when using pythonw.exe
| 1.2 | 0 | 0 | 6,198 |
337,870 |
2008-12-03T16:54:00.000
| 2 | 0 | 1 | 1 |
python,multithreading,subprocess
| 25,453,133 | 3 | false | 0 | 0 |
This is an old question, but the same problem happened with pyInstaller too.
In the truth, this will happen with any framework that converts code in python for exe without console.
In my tests, I observed that if I use the flag "console=True" into my spec file (pyInstaller) the error no longer occurs. .
The solution was follow the tip of Piotr Lesnicki.
| 2 | 5 | 0 |
I have some Python code that works correctly when I use python.exe to run it, but fails if I use pythonw.exe.
def runStuff(commandLine):
outputFileName = 'somefile.txt'
outputFile = open(outputFileName, "w")
try:
result = subprocess.call(commandLine, shell=True, stdout=outputFile)
except:
print 'Exception thrown:', str(sys.exc_info()[1])
myThread = threading.Thread(None, target=runStuff, commandLine=['whatever...'])
myThread.start()
The message I get is:
Exception thrown: [Error 6] The handle is invalid
However, if I don't specify the 'stdout' parameter, subprocess.call() starts okay.
I can see that pythonw.exe might be redirecting output itself, but I can't see why I'm blocked from specifying stdout for a new thread.
|
Python subprocess.call() fails when using pythonw.exe
| 0.132549 | 0 | 0 | 6,198 |
338,103 |
2008-12-03T17:56:00.000
| 4 | 0 | 1 | 0 |
python,macos,configuration,emacs,ipython
| 1,607,236 | 3 | false | 0 | 0 |
also ipython wont load with the official python.el being used with emacs 23.1.1
| 2 | 11 | 0 |
I'm running Emacs 22.1.1 and IPython 0.9.1 on OS X and I'd like to be able to run lines/methods/snippets of Python code from my current buffer on demand inside an IPython interpreter.
What do I need to do to get this working?
|
How do I use IPython as my Emacs Python interpreter?
| 0.26052 | 0 | 0 | 5,820 |
338,103 |
2008-12-03T17:56:00.000
| 0 | 0 | 1 | 0 |
python,macos,configuration,emacs,ipython
| 26,387,688 | 3 | false | 0 | 0 |
python-mode.el supports IPython natively.
Just make sure shebang doesn't point to another interpreter.
In this case:
either call a command with ending "-ipython", which will override shebang
customize "ipython" as default interpreter and set `py-force-py-shell-name-p'. This might be done also via menu
Python/.../Switches
| 2 | 11 | 0 |
I'm running Emacs 22.1.1 and IPython 0.9.1 on OS X and I'd like to be able to run lines/methods/snippets of Python code from my current buffer on demand inside an IPython interpreter.
What do I need to do to get this working?
|
How do I use IPython as my Emacs Python interpreter?
| 0 | 0 | 0 | 5,820 |
338,767 |
2008-12-03T21:26:00.000
| 12 | 0 | 1 | 0 |
python,indentation
| 510,920 | 5 | false | 0 | 0 |
:retab will swap tab with spaces, and :retab! will swap spaces with tab. 1 tab = 4 spaces, 4 spaces = 1 tab, depending on your tab setting.
| 3 | 12 | 0 |
I have a some .py files that use spaces for indentation, and I'd like to convert them to tabs.
I could easily hack together something using regexes, but I can think of several edge cases where this approach could fail. Is there a tool that does this by parsing the file and determining the indentation level the same way the python interpreter does?
|
Tool to convert python indentation from spaces to tabs?
| 1 | 0 | 0 | 14,275 |
338,767 |
2008-12-03T21:26:00.000
| 16 | 0 | 1 | 0 |
python,indentation
| 338,929 | 5 | false | 0 | 0 |
Python includes a script for the opposite (tabs to spaces). It's C:\Python24\Tools\Scripts\reindent.py for me
| 3 | 12 | 0 |
I have a some .py files that use spaces for indentation, and I'd like to convert them to tabs.
I could easily hack together something using regexes, but I can think of several edge cases where this approach could fail. Is there a tool that does this by parsing the file and determining the indentation level the same way the python interpreter does?
|
Tool to convert python indentation from spaces to tabs?
| 1 | 0 | 0 | 14,275 |
338,767 |
2008-12-03T21:26:00.000
| 3 | 0 | 1 | 0 |
python,indentation
| 338,966 | 5 | false | 0 | 0 |
In emacs, M-x tabify will convert spaces to tabs where possible. You'll probably want to set the tab-width variable appropriately.
I don't know if this addresses your concern that spaces be interpreted in the same way as the python interpreter, but you could always load up python-mode and use M-x indent-region.
| 3 | 12 | 0 |
I have a some .py files that use spaces for indentation, and I'd like to convert them to tabs.
I could easily hack together something using regexes, but I can think of several edge cases where this approach could fail. Is there a tool that does this by parsing the file and determining the indentation level the same way the python interpreter does?
|
Tool to convert python indentation from spaces to tabs?
| 0.119427 | 0 | 0 | 14,275 |
339,217 |
2008-12-04T00:17:00.000
| 2 | 0 | 1 | 0 |
python,dsl,dsl-tools
| 343,028 | 8 | false | 0 | 0 |
DSLs are a good thing, so you don't need to defend yourself :-)
However, have you considered an internal DSL ? These have so many pros versus external (parsed) DSLs that they're at least worth consideration. Mixing a DSL with the power of the native language really solves lots of the problems for you, and Python is not really bad at internal DSLs, with the with statement handy.
| 1 | 6 | 0 |
I am writing a game in python and have decided to create a DSL for the map data files. I know I could write my own parser with regex, but I am wondering if there are existing python tools which can do this more easily, like re2c which is used in the PHP engine.
Some extra info:
Yes, I do need a DSL, and even if I didn't I still want the experience of building and using one in a project.
The DSL contains only data (declarative?), it doesn't get "executed". Most lines look like:
SOMETHING: !abc @123 #xyz/123
I just need to read the tree of data.
|
Writing a compiler for a DSL in python
| 0.049958 | 0 | 0 | 8,510 |
340,128 |
2008-12-04T10:21:00.000
| 0 | 1 | 0 | 0 |
c#,python,unit-testing,ironpython
| 342,457 | 8 | false | 0 | 1 |
Very interesting.
What would happen if you write all your code with IronPython (not just the unit tests)? Would you end up with approximately 10 times less code?
Maybe I should learn IronPython too.
| 6 | 13 | 0 |
We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.
Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.
|
IronPython For Unit Testing over C#
| 0 | 0 | 0 | 3,355 |
340,128 |
2008-12-04T10:21:00.000
| 0 | 1 | 0 | 0 |
c#,python,unit-testing,ironpython
| 443,959 | 8 | false | 0 | 1 |
I gotta go with Will and Jon..
I would prefer my tests be in the same language as the code I'm testing; it causes fewer cognitive context switches. But maybe I'm just not as mentally agile as I once was.
Jon
| 6 | 13 | 0 |
We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.
Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.
|
IronPython For Unit Testing over C#
| 0 | 0 | 0 | 3,355 |
340,128 |
2008-12-04T10:21:00.000
| 3 | 1 | 0 | 0 |
c#,python,unit-testing,ironpython
| 342,490 | 8 | false | 0 | 1 |
Actually testing is a great opportunity to try integrating a new language. Languages like Python shine especially well in testing, and it's a low risk project to try - the worst case is not too bad at all.
As far as experience testing another language in Python, I've tested C and C++ systems like this and it was excellent. I think it's definitely worth a shot.
What Jon says is true, though - the level of tooling for Python in general, and IronPython in particular, is nowhere near that of C#. How much that affects you is something you'll find out in your pilot.
| 6 | 13 | 0 |
We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.
Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.
|
IronPython For Unit Testing over C#
| 0.07486 | 0 | 0 | 3,355 |
340,128 |
2008-12-04T10:21:00.000
| 3 | 1 | 0 | 0 |
c#,python,unit-testing,ironpython
| 341,683 | 8 | false | 0 | 1 |
Python being a much less verbose language than C# might actually lower the barrier to writing unit tests since there is still a lot of developers that are resistant to doing automated unit testing in general. Introducing and having them use a language like IronPython that typically tends to take less time to write the equivalent code in C# might actually encourage more unit tests to be written which is always a good thing.
Plus, by using IronPython for your test code, you might end up with less lines of code (LOC) for your project overall meaning that your unit tests might be more likely to be maintained in the long run versus being ignored and/or discarded.
| 6 | 13 | 0 |
We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.
Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.
|
IronPython For Unit Testing over C#
| 0.07486 | 0 | 0 | 3,355 |
340,128 |
2008-12-04T10:21:00.000
| 6 | 1 | 0 | 0 |
c#,python,unit-testing,ironpython
| 346,907 | 8 | false | 0 | 1 |
Python is excellent for UnitTesting C# code. Our app is 75% in Python and 25% C#(Python.Net), and our unit tests are 100% python.
I find that it's much easier to make use of stubs and mocks in Python which is probably one of the most critical components that enable one to write effective unittests.
| 6 | 13 | 0 |
We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.
Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.
|
IronPython For Unit Testing over C#
| 1 | 0 | 0 | 3,355 |
340,128 |
2008-12-04T10:21:00.000
| 2 | 1 | 0 | 0 |
c#,python,unit-testing,ironpython
| 340,152 | 8 | false | 0 | 1 |
There's an obvious disadvantage which is that everyone working on the code now needs to be proficient in two languages, not just one. I'm fairly hairy but not very pointy, but I do see why managers might be sceptical.
| 6 | 13 | 0 |
We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.
Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.
|
IronPython For Unit Testing over C#
| 0.049958 | 0 | 0 | 3,355 |
340,318 |
2008-12-04T11:48:00.000
| 14 | 1 | 0 | 0 |
php,python
| 340,338 | 11 | true | 1 | 0 |
You need to take some parts into mind here,
What will you gain from re-writing
Is it an economically wise decision
Will the code be easier to handle for new programmers
Performance-wise, will this be a good option?
These four points is something that is important, will the work be more efficient after you re-write the code? Probably. But will it be worth the cost of re-development?
One important step to follow, if you decide to re-write, make 3 documents, first Analyze the project, what needs to be done? How should everything work? Then put up a document with Requirements, what specificly do we need and how should this be done? Last but not least, the design document, where you put all your final class diagrams, the system operations and how the design and flow of the page should work.
This will help a new developer, and old ones, to actually think about "do we really need to re-write?".
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 1.2 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 1 | 1 | 0 | 0 |
php,python
| 340,792 | 11 | false | 1 | 0 |
As others have said, re-writing will take a lot longer than you think and fixing all the bugs and making use everything worked like in the old version will take even longer. Chances are you are better off simply improving and refactoring the php code you have. There are only a few good reasons to port a project from one language to another:
Performance. Some languages are simply faster than others, and there comes a point where there is nothing left to optimize and throwing hardware at the problem ceases to be effective.
Maintainability. Sometimes it is hard to find good people who know some obscure language which your legacy code is written in. In those cases it might be a good idea to re-write it in a more popular language to ease maintenance down the road.
Porting to a different platform. If you all of a sudden need to make your old VB program run on OS X and Linux as well as Windows then you’re probably looking at a re-write in a different language
In your case it doesn't seem like any of the above points hold. Of course if it's an unimportant app and you want to do it for the learning experience then by all means go for it, but from a business or economic point of view I'd take a long hard look at what such a re-write will cost and what exactly you hope to gain.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0.01818 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 0 | 1 | 0 | 0 |
php,python
| 340,719 | 11 | false | 1 | 0 |
Other issues include how business critical are the applications and how hard will it be to find maintainers. If the pages are hobbies of yours then I don't see a reason why you shouldn't rewrite them since if you introduce bugs or the rewrite doesn't go according to schedule a business won't lose money. If the application is central to a business I wouldn’t rewrite it unless you are running into limitations with the current design that can not be overcome with out a complete rewrite at which point the language choice is secondary to the fact that you need to throw out several years of work because it’s not maintainable and no longer meets your needs.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 1 | 1 | 0 | 0 |
php,python
| 340,685 | 11 | false | 1 | 0 |
If you are going to add more features to the code you already have working, then it might be a good idea to port it to python. After all, it will get you increased productivity. You just have to balance it, whether the rewriting task will not outweigh the potential gain...
And also, when you do that, try to unittest as much as you can.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0.01818 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 2 | 1 | 0 | 0 |
php,python
| 340,342 | 11 | false | 1 | 0 |
Well, it depends... ;) If you're going to use the old code together with new Python code, it might be useful, not so much for speed but for easier integration. But usually: "If it ain't broke, don't fix it". Allso rewriting can result in better code, but only do it if you need to.
As a hobby project of course it's worth it, cause the process is the goal.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0.036348 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 1 | 1 | 0 | 0 |
php,python
| 341,834 | 11 | false | 1 | 0 |
I did a conversion between a PHP site and a Turbogears(Python) site for my company. The initial reason for doing so was two fold, first so a redesign would be easier and second that features could be easily added. It did take a while to get the full conversion done, but what we end up with was a very flexible back end and an even more flexible and readable front end. We've added several features that would have been very hard in PHP and we are currently doing a complete overhaul of the front end, which is turning out to be very easy.
In short it's something I would recommend, and my boss would probably say the same thing. Some people here are making good points though. Python isn't as fast as what PHP can give you, but what it lacks in performance it more then makes up for in versatility.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0.01818 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 2 | 1 | 0 | 0 |
php,python
| 340,604 | 11 | false | 1 | 0 |
As others have said, look at why you are doing it.
For instance, at work I am rewriting our existing inventory/sales system to a Python/django backend. Why? Because the existing PHP code base is stale, and is going to scale poorly as we grow our business (plus it was built when our business model was different, then patched up to match our current needs which resulted in some spaghetti code)
So basically, if you think you're going to benefit from it in ways that aren't just "sweet this is in python now!" then go for it.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0.036348 | 0 | 0 | 1,366 |
340,318 |
2008-12-04T11:48:00.000
| 1 | 1 | 0 | 0 |
php,python
| 340,334 | 11 | false | 1 | 0 |
Is your aim purely to improve the applications, or is it that you want to learn/work with Python?
If it's the first, I would say you should stick with PHP, since you already know that.
| 8 | 6 | 0 |
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to write things more robustly.
Is this worth the effort?
|
Is rewriting a PHP app into Python a productive step?
| 0.01818 | 0 | 0 | 1,366 |
341,138 |
2008-12-04T16:06:00.000
| 4 | 0 | 1 | 1 |
python,windows
| 341,369 | 2 | true | 0 | 0 |
found it
win32api.InitiateSystemShutdown("localhost", "Maintenance Reboot", 60, 1, 1)
| 1 | 4 | 0 |
How can I reboot a Windows XP64 Machine in a Python Script? This machine does not have the "shutdown" or "restart" executables available.
|
How can I reboot a Windows XP64 Machine in a Python Script?
| 1.2 | 0 | 0 | 521 |
341,184 |
2008-12-04T16:18:00.000
| 1 | 0 | 1 | 1 |
python,windows,python-3.x,compatibility
| 341,231 | 20 | false | 0 | 0 |
I think there is an option to setup the windows file association for .py files in the installer. Uncheck it and you should be fine.
If not, you can easily re-associate .py files with the previous version. The simplest way is to right click on a .py file, select "open with" / "choose program". On the dialog that appears, select or browse to the version of python you want to use by default, and check the "always use this program to open this kind of file" checkbox.
| 5 | 176 | 0 |
I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?
I want to play with Python 3 while still being able to run 2.x scripts on the same machine.
|
Can I install Python 3.x and 2.x on the same Windows computer?
| 0.01 | 0 | 0 | 244,252 |
341,184 |
2008-12-04T16:18:00.000
| 0 | 0 | 1 | 1 |
python,windows,python-3.x,compatibility
| 341,444 | 20 | false | 0 | 0 |
I would assume so, I have Python 2.4, 2.5 and 2.6 installed side-by-side on the same computer.
| 5 | 176 | 0 |
I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?
I want to play with Python 3 while still being able to run 2.x scripts on the same machine.
|
Can I install Python 3.x and 2.x on the same Windows computer?
| 0 | 0 | 0 | 244,252 |
341,184 |
2008-12-04T16:18:00.000
| 1 | 0 | 1 | 1 |
python,windows,python-3.x,compatibility
| 453,580 | 20 | false | 0 | 0 |
You should make sure that the PATH environment variable doesn't contain both python.exe files ( add the one you're currently using to run scripts on a day to day basis ) , or do as Kniht suggested with the batch files .
Aside from that , I don't see why not .
P.S : I have 2.6 installed as my "primary" python and 3.0 as my "play" python . The 2.6 is included in the PATH . Everything works fine .
| 5 | 176 | 0 |
I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?
I want to play with Python 3 while still being able to run 2.x scripts on the same machine.
|
Can I install Python 3.x and 2.x on the same Windows computer?
| 0.01 | 0 | 0 | 244,252 |
341,184 |
2008-12-04T16:18:00.000
| 4 | 0 | 1 | 1 |
python,windows,python-3.x,compatibility
| 341,216 | 20 | false | 0 | 0 |
As far as I know Python runs off of the commandline using the PATH variable as opposed to a registry setting.
So if you point to the correct version on your PATH you will use that. Remember to restart your command prompt to use the new PATH settings.
| 5 | 176 | 0 |
I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?
I want to play with Python 3 while still being able to run 2.x scripts on the same machine.
|
Can I install Python 3.x and 2.x on the same Windows computer?
| 0.039979 | 0 | 0 | 244,252 |
341,184 |
2008-12-04T16:18:00.000
| 0 | 0 | 1 | 1 |
python,windows,python-3.x,compatibility
| 42,079,860 | 20 | false | 0 | 0 |
I am just starting out with python now. I'm reading Zed Shaw's book "Learn Python the Hard Way" which requires python version 2.x but am also taking a class that requires python 3.x
So here is what I did.
Download python 2.7
run power shell (should already be installed on windows)
run python IN POWERSHELL (if it doesn't recognize then go to step 4)
Only if powershell doesn't recognize python 2.7 type in the following:
"[ENVIRONMENT]::SETENVIRONMENTVARIABLE("PATH", "$ENV:PATH;C:\PYTHON27", "USER")"
(no outside quotes)
Now type python and you should see it say python 2.7 blah blah blah
NOW for python 3.x
Simple, python 3.x download comes with python for windows app. SO simply pin the Python for Windows app to your task bar, or create shortcut to the desktop and you are done!
Open Python for Windows for 3.x
Open Powershell for python 2.x
I hope this helps!
| 5 | 176 | 0 |
I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?
I want to play with Python 3 while still being able to run 2.x scripts on the same machine.
|
Can I install Python 3.x and 2.x on the same Windows computer?
| 0 | 0 | 0 | 244,252 |
342,425 |
2008-12-04T23:16:00.000
| 4 | 0 | 1 | 0 |
python,deployment,shared-libraries,projects-and-solutions
| 342,442 | 3 | false | 0 | 0 |
"explicitly tested against App1,2,3 every time there was a new library" actually isn't that onerous.
Two things.
You need a formal set of API unit tests that the library must pass. This is just the API, not every nuance of functionality. If this passes, then your changes are good to go. If this fails, your changes broke the API.
You also need a set of unit tests for functionality, separate from the API. This is bigger, and might be classified as "onerous".
Once you start unit testing, you get addicted. Once you have reasonably complete tests, this problem is easy to manage.
| 1 | 4 | 0 |
Our company (xyz) is moving a lot of our Flash code to Python.
In Flash, we have a shared library between our Flash apps - package xyz. We can make changes to the package without fear of breaking other apps when they are deployed because Flash compiles their code and includes the contents of the library. We deploy the final SWF via RPM, and we're done. Updates to App1 and App2 won't ever break App3.
How would you approach this in Python, the shared library dependency.
App1, App2 and App3, could all require xyz-lib.rpm, and all use the same library files, but an updated xyz-lib.rpm would have to be explicitly tested against App1,2,3 every time there was a new library, and this is just onerous.
My current favorite solution - I could make app1.rpm include the library from when it was packaged - effectively some sort of static linking of the library. This, however, feels inelegant. (although the only additional cost is hard drive space == cheap.)
I know that solid management of the shared library is probably the best solution, but I keep trying to factor in that all the developers are human, and will make mistakes. We're going to make mistakes, and I don't want a deployment of app1 to break app2 and app3 - it's just a lot more to test and debug for.
|
Best way of sharing/managing our internal python library between applications
| 0.26052 | 0 | 0 | 1,065 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.