Available Count
int64 1
31
| AnswerCount
int64 1
35
| GUI and Desktop Applications
int64 0
1
| Users Score
int64 -17
588
| Q_Score
int64 0
6.79k
| Python Basics and Environment
int64 0
1
| Score
float64 -1
1.2
| Networking and APIs
int64 0
1
| Question
stringlengths 15
7.24k
| Database and SQL
int64 0
1
| Tags
stringlengths 6
76
| CreationDate
stringlengths 23
23
| System Administration and DevOps
int64 0
1
| Q_Id
int64 469
38.2M
| Answer
stringlengths 15
7k
| Data Science and Machine Learning
int64 0
1
| ViewCount
int64 13
1.88M
| is_accepted
bool 2
classes | Web Development
int64 0
1
| Other
int64 1
1
| Title
stringlengths 15
142
| A_Id
int64 518
72.2M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 | 4 | 0 | 1 | 2 | 1 | 1.2 | 0 |
I receive some data as a string. I need to write the data to a file, but the problem is that sometimes the data is compressed/zipped and sometimes it's just plain text. I need to determine the content-type so I know whether to write it to a .txt file or a .tgz file. Any ideas on how to accomplish this? Can I use mime type somehow even though my data is a string, not a file?
Thanks.
| 0 |
python,string,content-type
|
2011-01-20T20:52:00.000
| 0 | 4,752,451 |
Both gzip and zip use distinct headers before compressed data, rather unlikely for human-readable strings. If the choice is only between these, you can make a faster check than mimetypes would provide.
| 0 | 2,383 | true | 0 | 1 |
How to determine content type of a string
| 4,752,565 |
1 | 3 | 0 | 1 | 4 | 1 | 0.066568 | 0 |
I'm working on a Python script that reads an XML file encoded with UTF-8, does some manipulation with it and saves it to Google's Datastore (it's an App Engine program).
The way I'm reading and parsing the files is just with file.readline() and a few regular expressions. The only problem is that the file I'm working with has characters from a lot of different languages in it, so for example, it might have an é or Å or Russian or Greek characters.
I was getting an error like this at first: "UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)." I then tried switching the encoding on the file open to "ISO-8859-15" which gets rid of the error but the outputted characters aren't displayed right.
So my question is: how to work with a file encoded in UTF-8 in Python without Python getting stuck on all of the special characters in the file? I hope this was clear enough, and thanks in advance for any advice.
| 0 |
python,google-app-engine,file-io,localization
|
2011-01-20T21:26:00.000
| 0 | 4,752,784 |
You say you changed the encoding you use with the file to ISO-8859-1. Did you try changing it to UTF-8?
| 0 | 629 | false | 0 | 1 |
Doing File I/O in Python with non-ASCII Characters
| 4,753,511 |
3 | 8 | 0 | 0 | 21 | 0 | 0 | 0 |
I'm trying to write a pretty heavy duty math-based project, which will parse through about 100MB+ data several times a day, so, I need a fast language that's pretty easy to use. I would have gone with C, but, getting a large project done in C is very difficult, especially with the low level programming getting in your way. So, I was about python or java. Both are well equiped with OO features, so I don't mind that. Now, here are my pros for choosing python:
Very easy to use language
Has a pretty large library of useful stuff
Has an easy to use plotting library
Here are the cons:
Not exactly blazing
There isn't a native python neural network library that is active
I can't close source my code without going through quite a bit of trouble
Deploying python code on clients computers is hard to deal with, especially when clients are idiots.
Here are the pros for choosing Java:
Huge library
Well supported
Easy to deploy
Pretty fast, possibly even comparable to C++
The Encog Neural Network Library is really active and pretty awesome
Networking support is really good
Strong typing
Here are the cons for Java:
I can't find a good graphing library like matplotlib for python
No built in support for big integers, that means another dependency (I mean REALLY big integers, not just math.BigInteger size)
File IO is kind of awkward compared to Python
Not a ton of array manipulating or "make programming easy" type of features that python has.
So, I was hoping you guys can tell me what to use. I'm equally familiar with both languages. Also, suggestions for other languages is great too.
EDIT: WOW! you guys are fast! 30 mins at 10 responses!
| 0 |
java,python,math,stocks
|
2011-01-21T13:47:00.000
| 0 | 4,759,485 |
What is more important for you?
If it's rapid application development, I found Python significantly easier to code for than Java - and I was just learning Python, while I had been coding on Java for years.
If it's application speed and the ability to reuse existing code, then you should probably stick with Java. It's reasonably fast and many research efforts at the moment use Java as their language of choice.
| 1 | 12,225 | false | 0 | 1 |
Java or Python for math?
| 4,759,549 |
3 | 8 | 0 | 1 | 21 | 0 | 0.024995 | 0 |
I'm trying to write a pretty heavy duty math-based project, which will parse through about 100MB+ data several times a day, so, I need a fast language that's pretty easy to use. I would have gone with C, but, getting a large project done in C is very difficult, especially with the low level programming getting in your way. So, I was about python or java. Both are well equiped with OO features, so I don't mind that. Now, here are my pros for choosing python:
Very easy to use language
Has a pretty large library of useful stuff
Has an easy to use plotting library
Here are the cons:
Not exactly blazing
There isn't a native python neural network library that is active
I can't close source my code without going through quite a bit of trouble
Deploying python code on clients computers is hard to deal with, especially when clients are idiots.
Here are the pros for choosing Java:
Huge library
Well supported
Easy to deploy
Pretty fast, possibly even comparable to C++
The Encog Neural Network Library is really active and pretty awesome
Networking support is really good
Strong typing
Here are the cons for Java:
I can't find a good graphing library like matplotlib for python
No built in support for big integers, that means another dependency (I mean REALLY big integers, not just math.BigInteger size)
File IO is kind of awkward compared to Python
Not a ton of array manipulating or "make programming easy" type of features that python has.
So, I was hoping you guys can tell me what to use. I'm equally familiar with both languages. Also, suggestions for other languages is great too.
EDIT: WOW! you guys are fast! 30 mins at 10 responses!
| 0 |
java,python,math,stocks
|
2011-01-21T13:47:00.000
| 0 | 4,759,485 |
If those are the choices, then Java should be the faster for math intensive work. It is compiled (although yes it is still running byte code).
Exelian mentions NumPy. There's also the SciPy package. Both are worth looking at but only really seem to give speed improvements for work with lots of arrays and vector processing.
When I tried using these with NLTK for a math-intensive routine, I found there wasn't that much of a speedup.
For math intensive work these days, I'd be using C/C++ or C# (personally I prefer C# over Java although that shouldn't affect your decision). My first employer out of univ. paid me to use Fortran for stuff that is almost certainly more math intensive than anything you're thinking of. Don't laugh - the Fortran compilers are some of the best for math processing on heavy iron.
| 1 | 12,225 | false | 0 | 1 |
Java or Python for math?
| 4,759,596 |
3 | 8 | 0 | 0 | 21 | 0 | 0 | 0 |
I'm trying to write a pretty heavy duty math-based project, which will parse through about 100MB+ data several times a day, so, I need a fast language that's pretty easy to use. I would have gone with C, but, getting a large project done in C is very difficult, especially with the low level programming getting in your way. So, I was about python or java. Both are well equiped with OO features, so I don't mind that. Now, here are my pros for choosing python:
Very easy to use language
Has a pretty large library of useful stuff
Has an easy to use plotting library
Here are the cons:
Not exactly blazing
There isn't a native python neural network library that is active
I can't close source my code without going through quite a bit of trouble
Deploying python code on clients computers is hard to deal with, especially when clients are idiots.
Here are the pros for choosing Java:
Huge library
Well supported
Easy to deploy
Pretty fast, possibly even comparable to C++
The Encog Neural Network Library is really active and pretty awesome
Networking support is really good
Strong typing
Here are the cons for Java:
I can't find a good graphing library like matplotlib for python
No built in support for big integers, that means another dependency (I mean REALLY big integers, not just math.BigInteger size)
File IO is kind of awkward compared to Python
Not a ton of array manipulating or "make programming easy" type of features that python has.
So, I was hoping you guys can tell me what to use. I'm equally familiar with both languages. Also, suggestions for other languages is great too.
EDIT: WOW! you guys are fast! 30 mins at 10 responses!
| 0 |
java,python,math,stocks
|
2011-01-21T13:47:00.000
| 0 | 4,759,485 |
The Apache Commons Math picked up where JAMA left off. They are quite capable for scientific computing.
So is Python - NumPy and SciPy are excellent. I also like the fact that Python is a hybrid of object-orientation and functional programming. Functional programming is awfully handy for numerical methods.
I'd recommend using the one that you know best, but if the choice is a toss up I might lean towards Python.
| 1 | 12,225 | false | 0 | 1 |
Java or Python for math?
| 4,765,700 |
7 | 7 | 0 | 1 | 4 | 1 | 0.028564 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
Dumb programmers are good programmers. I've maintained code of people that is much smarter than me, their code is an unreadable mess. Funnily, the same things happen with people who can't program except that the really smart programmers code actually works.
In both cases it's hard for other people to take over, and at the same time the smart programmer has become bored and are doing something else.
A good programmer writes "dumb", easy to understand code that he can give to somebody else to maintain, so he can go on doing more interesting things instead of maintaining that annoying piece of huge software that is seriously in need of a refactoring.
Programmers should be smart. Code should be dumb.
| 0 | 932 | false | 0 | 1 |
Which language should I stick with
| 4,781,086 |
7 | 7 | 0 | 2 | 4 | 1 | 0.057081 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
It really depends on what kind of work you are planning to do. But, really, most high level programming languages operate on very similar principles. If you understand all the underlying concepts, switching from one language to another is just a matter of changing your syntax.
Still, if you're insistent on sticking entirely with one language, I'm a fan of java. I think you're right that C++ is a little clunky for large tasks. You can probably accomplish anything with java that you can with python, but it trades some of the smoothness of python for a more direct relationship between what you're doing and what's actually going on. (At least, that's my opinion, as someone who has spent a LOT more time using java than using python. Experts in both might disagree with me.)
| 0 | 932 | false | 0 | 1 |
Which language should I stick with
| 4,779,041 |
7 | 7 | 0 | 4 | 4 | 1 | 0.113791 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
I am of the opinion that you don't "leave" a language. It's still in your toolbox, just possibly not used as often. I would recommend looking at it more like:
"i'm thinking of broadening my options by learning a new language."
Just this past week I have worked in C#, Java, Bash, Python and Javascript. When you're looked at as a problem solver, you never know what you'll be asked to help with next month, but you know you'll be doing something...
| 0 | 932 | false | 0 | 1 |
Which language should I stick with
| 4,779,017 |
7 | 7 | 0 | 2 | 4 | 1 | 0.057081 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
I personally keep my main activity on C/C++/Assembly, and explore other languages on the side. This is because my goals are to stay as sharp as possible, whether that be on problem solving part or hardware friendly side. Personally I find it much more exciting to be next to the hardware amongst other things. Also, when you code regularly in the latter languages, managing pointers, memory etc. become natural and intrinsically makes you that much better as a coder and even more so problem solver ;^).
Hope this helps!
| 0 | 932 | false | 0 | 1 |
Which language should I stick with
| 4,779,018 |
7 | 7 | 0 | 3 | 4 | 1 | 0.085505 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
I'd suggest looking into a more esoteric language, at least for a little while. Write up a small GUI in Smalltalk, or a utility in Common Lisp or Scheme. Don't just try to adapt your Java knowledge to those languages, really try to use the languages the way the Ron Jeffries and Paul Grahams of the world use them.
If you just want to learn something applicable in the job market, then those won't be as good as Python or C++. However, learning languages that are very different from languages that you already know should provide an interesting challenge, and permanently alter the way you think about programming.
| 0 | 932 | false | 0 | 1 |
Which language should I stick with
| 4,779,127 |
7 | 7 | 0 | 3 | 4 | 1 | 1.2 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
I have mostly experience in a few of domain-specific languages and a few general purpose languages (C, C++, Java, Delphi, etc.), and I have no experience with Python (only a general idea of it).
You must not judge languages on a basis of how hard they are. You say you have to consider the fact that you have to spend time debugging code to please the C++ compiler. I'm an experienced C++ programmer, and I can write several thousands of lines of code at a time, then compile and run, and everything works on the first try (well there are a few inevitable typos and stuff, like in any programming). So, that argument really only refers to your skill level in a programming language. I always favour C++ for any projects I have, because it is so effective (for me) to code in this language. That can surely factor in as a pragmatic view that you should program in the language in which you can actually be productive (in the short term).
But, when it comes to learning, you have to steer towards what seems applicable in your domain. I do artificial intelligence for controlling robots, so I need the hardware access and I need the complex programming constructs that OOP, GP and TMP offer. So, the C++ choice is a no-brainer for me. You have to ask what are the common tasks in your domain? Where do they stand on scales like low- vs. high-level, networking vs numerical analysis, user-oriented vs. computationally-oriented? What are the most widely used languages in your field (or the one you would like to get into)?
I also want to point out that, as a Linux user, a setup that seems quite prevalent amongst the open-source developers of the Linux software ecosystem is to implement low-level drivers in C, complex software in C++, and high-level software interfaces and plugins in Python. That's just what I seem to observe in many of the open-source software, and I think it makes sense that it seems to use the best sides of all three languages.. that's why I'm considering starting to learn Python on the side.
| 0 | 932 | true | 0 | 1 |
Which language should I stick with
| 4,779,510 |
7 | 7 | 0 | 13 | 4 | 1 | 1 | 0 |
I've got good experience in Java and web development with some experience in C++ also. Lately, I've been thinking of leaving Java (bored with it) for C++. Then came Python(didn't like Ruby). I find it too good to resist and started using it. But the C++ still stays in my mind.
Now I want to "stick" with one language to be fluent with it.
Python is great for quick programming but its too easy and I fear it would dumb me down. C++ is tougher but I doubt if I should use such a language where more time is wasted in keeping the compiler happy.
Which language should I stick with. Any comments?
| 0 |
c++,python,choice
|
2011-01-24T05:38:00.000
| 0 | 4,778,978 |
I suggest you don't worry about "sticking" with a language and learn to move in and out of whatever is the best solution for your problem.
The best programmers are simply great problem solvers - the particular language doesn't really matter.
| 0 | 932 | false | 0 | 1 |
Which language should I stick with
| 4,778,995 |
1 | 3 | 0 | 1 | 2 | 1 | 0.066568 | 0 |
I can't find the answer on SO but it's very likely that the argument has been already discussed.
I'm trying to write a quite small size program using the Python language. It's my first "real" experience with a dynamic language and I would prefer to do everything in the right way. One of the practice that I would try to apply since the beginning is unit-testing.
How can I quickly test that the parameters of a method are of the right type? Should I do it?
With right type I mean for instance to check that a method that works with float numbers is not called with a String. In this case consider the possibility that the method should obviously accept even integers and not only float.
| 0 |
python,unit-testing,dynamic-languages
|
2011-01-24T14:37:00.000
| 0 | 4,783,257 |
Unit testing with complete coverage is really the only way to handle any development work which relies on dynamic languages. Clearly it's very beneficial to have strong coverage tests for statically typed languages but in my experience it's even more important when you have dynamic typing.
If you aren't covering all the code that can run in your tests, then really you are asking for trouble. So you want to use a coverage analysis tool in tandem with your unit tests to prove that you are reaching all of your code.
Even that won't guard against all pitfalls – your tests really need to exercise all the possibly erroneous input data errors your program may receive.
| 0 | 313 | false | 0 | 1 |
How to deal with wrong parameters types in dynamic-languages?
| 4,783,323 |
2 | 3 | 0 | 3 | 2 | 1 | 0.197375 | 0 |
I'm gathering basic metadata for images - mainly their dimensions, although it'd be nice to get any other available metadata as well. The image formats I'm interested in are png, jpg, and gif.
I'm using PIL at the moment, but it occurred to me there may be a simpler way that doesn't involve external dependencies or binary libraries. Is there one?
| 0 |
python
|
2011-01-26T00:39:00.000
| 0 | 4,800,425 |
I don't think there is anything built in, but if you look up those file formats, you will find that the size is encoded near the beginning of the file.
You can use the struct module to parse just enough of the header to work out the size
| 0 | 1,574 | false | 0 | 1 |
Python: Simplest (non-PIL) way to get image metadata (mainly size)
| 4,800,509 |
2 | 3 | 0 | 1 | 2 | 1 | 1.2 | 0 |
I'm gathering basic metadata for images - mainly their dimensions, although it'd be nice to get any other available metadata as well. The image formats I'm interested in are png, jpg, and gif.
I'm using PIL at the moment, but it occurred to me there may be a simpler way that doesn't involve external dependencies or binary libraries. Is there one?
| 0 |
python
|
2011-01-26T00:39:00.000
| 0 | 4,800,425 |
Answer: No there is not a simpler way than using an external library.
If you are only going to care about one and one file format only, then yes. Then it's easy to implement something specific for that. But if you want to be generic, you need to support a lot of file formats, and then you don't want to do all that work yourself.
To simplify install of PIL, you might look at Pillow, a friendly fork§ that makes PIL easy_installable.
| 0 | 1,574 | true | 0 | 1 |
Python: Simplest (non-PIL) way to get image metadata (mainly size)
| 4,804,100 |
1 | 4 | 0 | 1 | 1 | 0 | 1.2 | 0 |
I would like to ideally set up a user interface for designing emails that include text, html, and images, and would like this interface to output the raw encoded email so I can then pipe it to my mail application, save it in a database, etc..
Are there any libraries that I could look at for generating raw emails, and/or the necessary HTML?
For example: You can create a document in MS Word (interface) and merge it with outlook to send. Ideally I'd like a Jquery based library that would let me visually create the mail, and output the result as a long string.
However, even any server-based libraries in any languages would be helpful: Javascript, Ruby, Python, Java, etc..
I think what I'm looking for is a mail generation library (or as mentioned in the answer below, a mime-generation framework
EDIT: I know this question is pretty general.. If it can be rephrased better let me know. If its like asking for a "Facebook", and naive and unrealizable, let me know. Useless comments that don't add anything not needed though
| 0 |
java,jquery,python,ruby,email
|
2011-01-26T10:30:00.000
| 0 | 4,803,499 |
Python has modules both for creating and sending emails in the standard library. Don't know about Java or Ruby. For generating HTML I'd use some HTML template language. There are tons of them for Python. Pick one you like.
| 0 | 220 | true | 1 | 1 |
What libraries exist for creating raw multipart emails?
| 4,803,954 |
1 | 3 | 1 | 0 | 1 | 0 | 0 | 0 |
I'm using the pyBluez module on Python 2.6 on WindowsXP. I'd like to get the RSSI of other bluetooth devices around.
I foudn some code but it makes use of _bluetooth, which I cannto find anywhere for Windows.
Is it available / is there another way to circumvent the problem, getting the RSSI without using _bluetooth?
Thank you all!
| 0 |
python,windows,bluetooth,rssi
|
2011-01-27T10:17:00.000
| 0 | 4,815,088 |
The _bluetooth module is a part of PyBluez. If you have installed a Windows release of PyBluez, it should work.
I don't know enough about Bluetooth to even know what "getting the RSSI without using it" means or why it should be a problem, so can't help you there. :)
| 0 | 1,917 | false | 0 | 1 |
RSSI with pyBluez on WindowsXP
| 4,815,494 |
1 | 1 | 1 | 1 | 1 | 0 | 1.2 | 0 |
I am trying to create a small application for Symbian mobile phones using Python. Being a beginner i am having some trouble in setting up the environment for development. I installed Symbian3 SDK,PyS60 Application Manager ( for creating the .sis files to be installed on phones) and python 2.5.2 . I created a small hello world program and created its equivalent .sis file. But when i try to install it in Symbian 3 SDK, it gives me a 'Python Run time Error' ; i suppose it is because there isnt any python installed on the SDK. But when i tried to install the PythonForS60.sis file, it gives me a certificate error. I tried downloading the file through SDK, again it gives me a certificate error. I tried certifying the application through SymbianSigned.com, then it gives this error
"The .sis file contains capabilities that are not permitted for Open Signed (Online)
FAILURE: Submitted .sis file uses a UID that is not allocated to the account holder matching this email address (0x20022ee8 )
FAILURE: Submitted .sis file uses a UID that is in protected range and is not allocated to the account holder matching this email address (0x20022ee8)" . Can somebody help me to solve this..??
| 0 |
python,symbian,pys60
|
2011-01-28T05:11:00.000
| 0 | 4,825,055 |
Open Application Manager on your Symbian phone, go to settings and select Software installation. Change it from Signed to All. This will allow you to install applications which don't have a certificate, such as the SIS file you just packaged.
Also note that PythonForS60 2.0 works only with Python 2.5.
| 0 | 900 | true | 0 | 1 |
Certificate Error on installing PythonForS60
| 4,825,096 |
1 | 3 | 0 | 1 | 5 | 1 | 0.066568 | 0 |
Will it continue the code after it's run? Or will it stop at that line until the script is done?
| 0 |
python,bash,shell
|
2011-01-28T09:36:00.000
| 1 | 4,826,686 |
You can use os.system or subprocess.Popen or subprocess.call but when using subprocess methods make sure you use shell=True. And executing it via system call in all these methods is blocking. The python script will complete and then go the next step.
| 0 | 32,061 | false | 0 | 1 |
Inside python code, how do I run a .sh script?
| 4,826,733 |
1 | 5 | 1 | 1 | 1 | 0 | 0.039979 | 0 |
I am trying to optimize the interaction between two scripts I have.
Two things I thought of are the c++ program not terminating unless you manually kill it, or generating all info in python before feeding it to c++.
Explanation of the problem:
What the scripts do:
C++ program (not made by me, and I can't program in c++ very well): takes a 7 number array and returns a single number, simple.
Python script (mine, and I can program a bit in python): generates those 7 number arrays, feeds them to the c++ program, waits for an answer and adds it to a list. It then makes the next array.
In theory, this works. However, as it is right now, it opens and closes the c++ program for each call. For one array that is no problem, but I'm trying to upscale to 25k arrays, and in the future to 6+ million arrays. Obviously it is then no longer feasible to open/close it each time, especially since the c++ program first has to load a 130mb VCD file to function.
Two options I thought of myself were to generate all arrays first in python, then feed them to the c++ program and then analyze all results. However, I wouldn't know how to do this with 6M arrays. It is not important however that the results I get back are in the same order as the arrays I feed in.
Second option I thought of was to make the c++ program not quit after each call. I can't program in c++ though so I don't know if this is possible, keeping it 'alive' so you can just feed arrays into it at times and get an answer.
(Note: I cannot program in anything else than python, and want to do this project in python. The c++ program cannot be translated to python for speed reasons.)
Thanks in advance, Max.
| 0 |
c++,python,optimization,interaction
|
2011-01-28T09:59:00.000
| 0 | 4,826,896 |
Firstly, just to be pedantic, there are no C++ scripts in normal use. C++ compiles, ultimately, to machine code, and the C++ program is properly referred to as a "program" and not a "script".
But to answer your question, you could indeed set up the C++ program to stay in memory, where it listens for connections and sends responses to your Python script. You'd want to study Unix IPC, particularly sockets.
Another way to approach it would be to incorporate what the C++ program does into your Python script, and forget about C++ altogether.
| 0 | 2,200 | false | 0 | 1 |
Python and C++ script interaction
| 4,827,083 |
1 | 1 | 0 | 1 | 2 | 0 | 0.197375 | 0 |
I am running a Python script which downloads PDF files from the FTP. The script when run manually works perfectly but when i put it in crontab in my ubuntu machine and execute it i get a an error [Errno 32] Broken pipe. Any idea why this happens and how do i handle this?
| 0 |
python
|
2011-01-29T10:49:00.000
| 1 | 4,836,450 |
Hi I dnt know y the error occurs but when i directed the print statements from my script to another file this error did not come and my script ran successfully
Example: Myscript.py > test.log
| 0 | 1,316 | false | 0 | 1 |
[Errno 32]Broken pipe in Python Script in Crontab
| 4,851,152 |
1 | 2 | 0 | 0 | 1 | 0 | 0 | 0 |
Is there a simple way or code to delete the account from a user? I want to delete the username, email address, first_name, last_name and the profile-data.
I do have two apps
Thanks!
| 0 |
python,django,web
|
2011-01-29T15:11:00.000
| 0 | 4,837,591 |
Can You Explain What kind of application you Use? If you use some kind of database with your application then simply run delete query with some specific condition
| 0 | 405 | false | 1 | 1 |
Simple way to delete users account?
| 4,837,665 |
3 | 3 | 0 | 3 | 6 | 1 | 1.2 | 0 |
I downloaded the Wikipedia article titles file which contains the name of every Wikipedia article. I need to search for all the article titles that may be a possible match. For example, I might have the word "hockey", but the Wikipedia article for hockey that I would want is "Ice_hockey". It should be a case-insensitive search too.
I'm using Python, and is there a more efficient way than to just do a line by line search? I'll be performing this search like 500 or a 1000 times per minute ideally. If line by line is my only option, are there some optimizations I can do within this?
I think there are several million lines in the file.
Any ideas?
Thanks.
| 0 |
python,string,search,large-files
|
2011-01-29T21:36:00.000
| 0 | 4,839,597 |
Greg's answer is good if you want to match on individual words. If you want to match on substrings you'll need something a bit more complicated, like a suffix tree (http://en.wikipedia.org/wiki/Suffix_tree). Once constructed, a suffix tree can efficiently answer queries for arbitrary substrings, so in your example it could match "Ice_Hockey" when someone searched for "hock".
| 0 | 2,903 | true | 0 | 1 |
most efficient way to find partial string matches in large file of strings (python)
| 4,840,359 |
3 | 3 | 0 | 4 | 6 | 1 | 0.26052 | 0 |
I downloaded the Wikipedia article titles file which contains the name of every Wikipedia article. I need to search for all the article titles that may be a possible match. For example, I might have the word "hockey", but the Wikipedia article for hockey that I would want is "Ice_hockey". It should be a case-insensitive search too.
I'm using Python, and is there a more efficient way than to just do a line by line search? I'll be performing this search like 500 or a 1000 times per minute ideally. If line by line is my only option, are there some optimizations I can do within this?
I think there are several million lines in the file.
Any ideas?
Thanks.
| 0 |
python,string,search,large-files
|
2011-01-29T21:36:00.000
| 0 | 4,839,597 |
If you've got a fixed data set and variable queries, then the usual technique is to reorganise the data set into something that can be searched more easily. At an abstract level, you could break up each article title into individual lowercase words, and add each of them to a Python dictionary data structure. Then, whenever you get a query, convert the query word to lower case and look it up in the dictionary. If each dictionary entry value is a list of titles, then you can easily find all the titles that match a given query word.
This works for straightforward words, but you will have to consider whether you want to do matching on similar words, such as finding "smoking" when the query is "smoke".
| 0 | 2,903 | false | 0 | 1 |
most efficient way to find partial string matches in large file of strings (python)
| 4,839,646 |
3 | 3 | 0 | 1 | 6 | 1 | 0.066568 | 0 |
I downloaded the Wikipedia article titles file which contains the name of every Wikipedia article. I need to search for all the article titles that may be a possible match. For example, I might have the word "hockey", but the Wikipedia article for hockey that I would want is "Ice_hockey". It should be a case-insensitive search too.
I'm using Python, and is there a more efficient way than to just do a line by line search? I'll be performing this search like 500 or a 1000 times per minute ideally. If line by line is my only option, are there some optimizations I can do within this?
I think there are several million lines in the file.
Any ideas?
Thanks.
| 0 |
python,string,search,large-files
|
2011-01-29T21:36:00.000
| 0 | 4,839,597 |
I'd suggest you put your data into an sqlite database, and use the SQL 'like' operator for your searches.
| 0 | 2,903 | false | 0 | 1 |
most efficient way to find partial string matches in large file of strings (python)
| 4,841,314 |
1 | 1 | 0 | 1 | 5 | 0 | 1.2 | 0 |
Is there any way to disable a module from being loaded on my system? Let's say i would like to restrict my users from accessing the subprocess or popen2 module. Something like PHP's 'disabled_functions' or any similar method to achieve the same thing.
| 0 |
python
|
2011-01-30T09:03:00.000
| 1 | 4,842,049 |
As @Thomas points out, blacklisting is a pretty poor mechanism for implementing any security mechanisms. Whitelisting is a much safer approach.
But a mechanism inside the interpreter isn't particularly excellent for any number of reasons: flaws in the interpreter that are exploitable at the source code level would allow users to walk right past any mechanisms built in at that level (and the PHP team asked Linux vendors to stop calling this a security problem, because (a) they fixed one of these every week and (b) trying to confine an untrusted user-supplied script is pretty much an impossible task -- use FastCGI or similar tools for potentially untrusted scripts).
The Python interpreter is probably not designed to handle malicious input, so don't treat it as such.
If you really want to confine what untrusted users can do with Python scripts, a few pieces of advice: Do not use mod_python or anything like it. Use FastCGI or similar tools that you let specify the user account that should run the script and won't execute the script as your webserver user. And learn how to configure SELinux or AppArmor to confine what that process can do -- an hour setting up one of these tools might save you huge headaches down the road, plus you get to laugh at all the cute little exploit attempts that fail.
| 0 | 3,339 | true | 0 | 1 |
DIsable Python module
| 4,842,172 |
1 | 1 | 0 | 7 | 3 | 1 | 1.2 | 0 |
Is it possible to acquire the global interpreter lock from python code? Or is that purely implemented in the C side?
| 0 |
python,multithreading,gil
|
2011-01-31T20:46:00.000
| 0 | 4,855,903 |
If your code executes then you have the GIL, no need to acquire it manually.
| 0 | 914 | true | 0 | 1 |
Acquiring the global interpreter lock from python
| 4,855,924 |
1 | 7 | 0 | 1 | 6 | 0 | 0.028564 | 0 |
I have a program that create files in a specific directory.
When those files are ready, I run Latex to produce a .pdf file.
So, my question is, how can I use this directory change as a trigger
to call Latex, using a shell script or a python script?
Best Regards
| 0 |
python,shell,latex
|
2011-02-01T12:08:00.000
| 1 | 4,862,346 |
Not much of a python man myself. But in a pinch, assuming you're on linux, you could periodically shell out and "ls -lrt /path/to/directory" (get the directory contents and sort by last modified), and compare the results of the last two calls for a difference. If so, then there was a change. Not very detailed, but gets the job done.
| 0 | 4,757 | false | 0 | 1 |
Check if the directory content has changed with shell script or python
| 4,862,410 |
1 | 3 | 0 | 1 | 1 | 0 | 1.2 | 0 |
I am trying to build Python from source and need to include the SSL module for my web scraper to work with it.
I ran into the problem of SSL not being found, so I downloaded and built OpenSSL from source. The problem is, I need to install the development libraries along with OpenSSL in order for Python to run the -lssl parameter correctly when running make. I can't seem to find any documentation on how to build OpenSSL with the development libs, even though I'm sure it's got to be something simple I'm just missing.
I must do this from source; with no package managers. I have my reasons.
EDIT:
I have changed a few of the python configuration settings to try and fix the problem, and this is the compile error I am getting now:
gcc -pthread -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.7.a -lpthread -ldl -lutil -L/home/[username]/openssl-src -lssl -lcrypto -lm
libpython2.7.a(posixmodule.o)(.text+0x4016): In function posix_tmpnam':<br />
./Modules/posixmodule.c:7346: warning: the use oftmpnam_r' is dangerous, better use mkstemp'
libpython2.7.a(posixmodule.o)(.text+0x3f76): In functionposix_tempnam':
./Modules/posixmodule.c:7301: warning: the use of tempnam' is dangerous, better usemkstemp'
./python: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
make: * [sharedmods] Error 127
The "no such file or directory" is being thrown looking for a file that does exist in the /home/[username]/openssl-src directory.
| 0 |
python,linux,openssl
|
2011-02-01T12:31:00.000
| 0 | 4,862,598 |
This answer doesn't EXACTLY answer my question, but I did find out what I needed to know so I will post it here. I had to change the location of the SSL files it was looking for to just /usr rather than /usr/local. RedHat by default has all the shared libraries in /usr/lib rather than /usr/local/lib, which is where it was looking by default.
| 0 | 2,122 | true | 0 | 1 |
Building OpenSSL to compile portable version of Python
| 4,927,502 |
2 | 3 | 0 | -1 | 0 | 0 | -0.066568 | 0 |
In Python, am using the LightBlue module for Bluetooth connectivity. How do I get the speed at which I am sending file to my phone from my laptop (Ubuntu)?
| 0 |
python,bluetooth
|
2011-02-01T14:27:00.000
| 1 | 4,863,727 |
You need a binding for the Bluetooth driver/OS service that handles the Bluetooth device.
Most drivers are written in C, some in C++. If you can get the source code/API or if it's provided you might be able to access it from python. You might need to code some custom binding to your OS service to do so.
| 0 | 1,146 | false | 0 | 1 |
Python bluetooth transfer speed?
| 4,863,792 |
2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 |
In Python, am using the LightBlue module for Bluetooth connectivity. How do I get the speed at which I am sending file to my phone from my laptop (Ubuntu)?
| 0 |
python,bluetooth
|
2011-02-01T14:27:00.000
| 1 | 4,863,727 |
The simplest solution is to figure out how large the file is, capture the system time before the transfer and after the transfer, and then do the math. To compute a more fine-grained transfer rate that changes over the course of the transfer, you would need to use the size of your transmit buffers and the time interval between sends.
| 0 | 1,146 | false | 0 | 1 |
Python bluetooth transfer speed?
| 4,870,002 |
2 | 4 | 0 | 6 | 13 | 1 | 1 | 0 |
I wrote a method that does some stuff and catches bad filenames. what should happen is if the path doesn't exist, it throws an IOError. however, it thinks my exception handling is bad syntax... why??
def whatever():
try:
# do stuff
# and more stuff
except IOError:
# do this
pass
whatever()
but before it even gets to calling whatever(), it prints the following:
Traceback (most recent call last):
File "", line 1, in
File "getquizzed.py", line 55
except IOError:
^
SyntaxError: invalid syntax
when imported...help?!
| 0 |
python,exception,exception-handling,try-catch,ioerror
|
2011-02-02T00:14:00.000
| 0 | 4,869,476 |
there's 1 more possible if you're privileged to have an older installation
and
you're using the 'as' syntax:
except IOError as ioe:
and
the parser's getting tripped up on 'as'.
Using as is the preferred syntax in Python 2.6 and better.
It's a syntax error in Python 2.5 and older. For pre-2.6, use this:
except IOError, ioe:
| 0 | 36,567 | false | 0 | 1 |
catching an IOError in python
| 18,236,796 |
2 | 4 | 0 | 2 | 13 | 1 | 0.099668 | 0 |
I wrote a method that does some stuff and catches bad filenames. what should happen is if the path doesn't exist, it throws an IOError. however, it thinks my exception handling is bad syntax... why??
def whatever():
try:
# do stuff
# and more stuff
except IOError:
# do this
pass
whatever()
but before it even gets to calling whatever(), it prints the following:
Traceback (most recent call last):
File "", line 1, in
File "getquizzed.py", line 55
except IOError:
^
SyntaxError: invalid syntax
when imported...help?!
| 0 |
python,exception,exception-handling,try-catch,ioerror
|
2011-02-02T00:14:00.000
| 0 | 4,869,476 |
Just missing something in your try block, i.e. pass or anything, otherwise it gives an indentation error.
| 0 | 36,567 | false | 0 | 1 |
catching an IOError in python
| 4,869,511 |
1 | 2 | 0 | 0 | 3 | 0 | 0 | 0 |
We have developed a web application running on Linux that is quite popular. We now wish to release it as an appliance so customers can run it internally on their own networks.
We are unsure of the best approach. We are flexible on areas such as: the Linux distro, whether it's a hardware or software only appliance. Does anyone have any advice on the best way to go about this? Links to any good resources on the subject? Questions we should be asking ourselves? Legal considerations for a commercial app? Security considerations?
UPDATE:
It's a Python based web application. We would like the user to be able to do everything via a web interface. No command line stuff etc.
| 0 |
python,appliance
|
2011-02-02T09:33:00.000
| 1 | 4,872,722 |
It depends on what langauge/tecnology application is written.
If it is java, release war file + tomcat/jboss.
If it is python, release eggs.
If it is php... not sure, probably just .tar.bz2.
Linux distro or virtual image mught be advantage, but I dislike using them, because they are usually does not fits to my infra (why do I have to install some custom debian-based distro to my rhel-only infrastructure?).
| 0 | 124 | false | 1 | 1 |
Considerations for moving our web app to an appliance
| 4,872,968 |
1 | 3 | 0 | 0 | 1 | 1 | 0 | 0 |
Trying to learn how to use the rpm-python module (i.e. "import rpm" on RHEL5). I can't find any tutorials that are complete or recent. Specifically regarding how to install and manage rpm's on a system. Anyone?
| 0 |
python,rpm,rhel5
|
2011-02-02T22:45:00.000
| 1 | 4,880,818 |
If you are on RHEL then you could seriously consider using the yum APIs instead of rpm-python directly ... the API is much easier to use.
| 0 | 658 | false | 0 | 1 |
Where is the most authoritative/complete source of documentation on rpm-python module?
| 4,935,001 |
4 | 7 | 0 | 0 | 13 | 1 | 0 | 0 |
We want to parse our huge C++ source tree to gain enough info to feed to another tool to make diagrams of class and object relations, discern the overall organization of things etc.
My best try so far is a Python script that scans all .cpp and .h files, runs regex searches to try to detect class declarations, methods, etc. We don't need a full-blown analyzer to capture every detail, or some heavy UML diagram generator - there's a lot of detail we'd like to ignore and we're inventing new types of diagrams. The script sorta works, but by gosh it's true: C++ is hard to parse!
So I wonder what tools exist for extracting the info we want from our sources? I'm not a language expert, and don't want something with a steep learning curve. Something we low-brow blue-collar programmer grunts can use :P
Python is preferred as one of the standard languages here, but it's not essential.
| 0 |
c++,python,parsing,code-analysis
|
2011-02-02T23:59:00.000
| 0 | 4,881,377 |
If you can bring yourself to run this analysis using a Windows-platform application, save yourself a lot of time and trouble, and spend $200 on Enterprise Architect by Sparx Systems (I have no affiliation with this company, just a satisfied customer). (Note: this should not be confused with Microsoft's own "Enterprise Architect" bundle for Visual Studio.)
EA can reverse-engineer a number of languages, including C++, C, Java, and Python, generating some very nice UML class diagrams. (EA comes in a number of different packages, Desktop is the cheapest but you have to by Professional, the 2nd cheapest, to get the code engineering feature included.) I also like the integration between the generated class diagrams and sequence diagramming, where you can drag a line between object lifelines and a menu of defined methods is presented to you based on the class definition of the target object. At my former consulting business, we used this tool quite a bit to develop system architectural proposals which we then included as part of our project bid (just copy/paste the diagram into a Word doc). It wont take long to make back your $200.
| 0 | 6,163 | false | 0 | 1 |
How to parse C++ source in Python?
| 4,882,258 |
4 | 7 | 0 | 3 | 13 | 1 | 0.085505 | 0 |
We want to parse our huge C++ source tree to gain enough info to feed to another tool to make diagrams of class and object relations, discern the overall organization of things etc.
My best try so far is a Python script that scans all .cpp and .h files, runs regex searches to try to detect class declarations, methods, etc. We don't need a full-blown analyzer to capture every detail, or some heavy UML diagram generator - there's a lot of detail we'd like to ignore and we're inventing new types of diagrams. The script sorta works, but by gosh it's true: C++ is hard to parse!
So I wonder what tools exist for extracting the info we want from our sources? I'm not a language expert, and don't want something with a steep learning curve. Something we low-brow blue-collar programmer grunts can use :P
Python is preferred as one of the standard languages here, but it's not essential.
| 0 |
c++,python,parsing,code-analysis
|
2011-02-02T23:59:00.000
| 0 | 4,881,377 |
Can you run a preprocessing step? Doxygen parses most C++ syntax and creates xml with all the relationships. Compilers also create debug databases (typically dwarf format from gcc and codeview format from MSC).
| 0 | 6,163 | false | 0 | 1 |
How to parse C++ source in Python?
| 4,881,763 |
4 | 7 | 0 | 1 | 13 | 1 | 0.028564 | 0 |
We want to parse our huge C++ source tree to gain enough info to feed to another tool to make diagrams of class and object relations, discern the overall organization of things etc.
My best try so far is a Python script that scans all .cpp and .h files, runs regex searches to try to detect class declarations, methods, etc. We don't need a full-blown analyzer to capture every detail, or some heavy UML diagram generator - there's a lot of detail we'd like to ignore and we're inventing new types of diagrams. The script sorta works, but by gosh it's true: C++ is hard to parse!
So I wonder what tools exist for extracting the info we want from our sources? I'm not a language expert, and don't want something with a steep learning curve. Something we low-brow blue-collar programmer grunts can use :P
Python is preferred as one of the standard languages here, but it's not essential.
| 0 |
c++,python,parsing,code-analysis
|
2011-02-02T23:59:00.000
| 0 | 4,881,377 |
From what you say of our requirements, Tony's answer of GccXML will probably be the best option. If that doesn't work, you could try to generate an outline of your program with cscope or ctags, and then work your way to the info you want from it's output.
| 0 | 6,163 | false | 0 | 1 |
How to parse C++ source in Python?
| 4,881,710 |
4 | 7 | 0 | 6 | 13 | 1 | 1 | 0 |
We want to parse our huge C++ source tree to gain enough info to feed to another tool to make diagrams of class and object relations, discern the overall organization of things etc.
My best try so far is a Python script that scans all .cpp and .h files, runs regex searches to try to detect class declarations, methods, etc. We don't need a full-blown analyzer to capture every detail, or some heavy UML diagram generator - there's a lot of detail we'd like to ignore and we're inventing new types of diagrams. The script sorta works, but by gosh it's true: C++ is hard to parse!
So I wonder what tools exist for extracting the info we want from our sources? I'm not a language expert, and don't want something with a steep learning curve. Something we low-brow blue-collar programmer grunts can use :P
Python is preferred as one of the standard languages here, but it's not essential.
| 0 |
c++,python,parsing,code-analysis
|
2011-02-02T23:59:00.000
| 0 | 4,881,377 |
You could check out GccXML and OpenC++, as well as doxygen.
| 0 | 6,163 | false | 0 | 1 |
How to parse C++ source in Python?
| 4,881,402 |
1 | 4 | 0 | 4 | 70 | 0 | 0.197375 | 0 |
Normally Fabric quits as soon as a run() call returns a non-zero exit code. For some calls, however, this is expected. For example, PNGOut returns an error code of 2 when it is unable to compress a file.
Currently I can only circumvent this limitation by either using shell logic (do_something_that_fails || true or do_something_that_fails || do_something_else), but I'd rather be able to keep my logic in plain Python (as is the Fabric promise).
Is there a way to check for an error code and react to it rather than having Fabric panic and die? I still want the default behaviours for other calls, so changing its behaviour by modifying the environment doesn't seem like a good option (and as far as I recall, you can only use that to tell it to warn instead of dying anyway).
| 0 |
python,error-handling,fabric
|
2011-02-03T16:11:00.000
| 1 | 4,888,568 |
Apparently messing with the environment is the answer.
fabric.api.settings can be used as a context manager (with with) to apply it to individual statements. The return value of run(), local() and sudo() calls isn't just the output of the shell command, but also has special properties (return_code and failed) that allow reacting to the errors.
I guess I was looking for something closer to the behaviour of subprocess.Popen or Python's usual exception handling.
| 0 | 44,680 | false | 0 | 1 |
Can I catch error codes when using Fabric to run() calls in a remote shell?
| 4,888,891 |
2 | 3 | 0 | 0 | 0 | 0 | 0 | 1 |
In another question I asked for "the best" language for a certain purpose. Realizing this goal was a bit too much to start, I simplified my idea :) But there were really useful language hints. So I decided on Scala for the desktop-app and consider between Perl and Python on the webserver.
I want to program something like an asynchronous chat (little bit like an email). So you start your program pick your name and add a friend with his unique id. Then you can write him a simple message and when your friends start up his pc, launches the "chat.exe" he receives the mail (internet is required) and is able to answer. No special functions, smiley's or text formatting, just simple for learning purpose.
My concept is: Use Scala for the "chat.exe" (Or is just a "chat.jar" possible?) which communicates via SOCKET with a Perl/Python Framework which handles the requests.
So you type "Hello there" and click on send. This message is transfered via SOCKET to a Perl/Python script which reads the request an put this message in a MySQL database. On the otherside the chat.exe of your friend checks for new messages and if there is one, the Perl/Python script transfer the message. Also via SOCKET.
Do you think this works out? Is SOCKET appropriate and fits in? Or perhaps REST? But I think for REST-Requests you have to use the URI (http://example.com/newmessage/user2/user3/Hi_how_are_you). This looks very unsecure.
Look forward to your comments!
Have a nice day,
Kurt
| 0 |
python,perl,sockets,scala,client-server
|
2011-02-03T21:25:00.000
| 0 | 4,891,911 |
To implement something like that you would need to go through a MQ System like perhaps ActiveMQ instead of using plain sockets.
| 0 | 609 | false | 0 | 1 |
Does this Scala Perl/Python architecture make sense
| 4,891,991 |
2 | 3 | 0 | 1 | 0 | 0 | 0.066568 | 1 |
In another question I asked for "the best" language for a certain purpose. Realizing this goal was a bit too much to start, I simplified my idea :) But there were really useful language hints. So I decided on Scala for the desktop-app and consider between Perl and Python on the webserver.
I want to program something like an asynchronous chat (little bit like an email). So you start your program pick your name and add a friend with his unique id. Then you can write him a simple message and when your friends start up his pc, launches the "chat.exe" he receives the mail (internet is required) and is able to answer. No special functions, smiley's or text formatting, just simple for learning purpose.
My concept is: Use Scala for the "chat.exe" (Or is just a "chat.jar" possible?) which communicates via SOCKET with a Perl/Python Framework which handles the requests.
So you type "Hello there" and click on send. This message is transfered via SOCKET to a Perl/Python script which reads the request an put this message in a MySQL database. On the otherside the chat.exe of your friend checks for new messages and if there is one, the Perl/Python script transfer the message. Also via SOCKET.
Do you think this works out? Is SOCKET appropriate and fits in? Or perhaps REST? But I think for REST-Requests you have to use the URI (http://example.com/newmessage/user2/user3/Hi_how_are_you). This looks very unsecure.
Look forward to your comments!
Have a nice day,
Kurt
| 0 |
python,perl,sockets,scala,client-server
|
2011-02-03T21:25:00.000
| 0 | 4,891,911 |
Use Scala for the "chat.exe" (Or is just a "chat.jar" possible?)
Step 1. Figure that out. Actually write some stuff and see what you can build.
which communicates via SOCKET with a Perl/Python Framework which handles the requests.
Not meaningful. All internet communication is done with sockets. Leave this sentence out and you don't lose any meaning.
This message is transfered via SOCKET to a Perl/Python script which reads the request an put this message in a MySQL database.
A little useful information. Sockets, however, go without saying.
On the otherside the chat.exe of your friend checks for new messages and if there is one, the Perl/Python script transfer the message. Also via SOCKET.
Right. Sockets, again, don't mean much.
On top of sockets there are dozens of protocols. FTP, Telnet, HTTP, SMTP, etc., etc.
Step 2 is to figure out which protocol you want to use. REST, by the way is a particular use of HTTP. You should really, really look very closely at HTTP and REST before dismissing them.
This looks very unsecure
Not clear why you're saying this. I can only guess that you don't know about HTTP security features.
A lazy programmer might do this.
Install Python, Django, MySQL-Python and Piston.
Define a Django Model, configure the defaults so that model is exposed as a secure RESTful set of services.
That's sort of it for the server side message GET, POST, PUT and DELETE are all provided by Django, Piston and the Django ORM layer. Authentication can be any of a variety of mechanisms. I'm a big fan of HTTP Digest authentication.
| 0 | 609 | false | 0 | 1 |
Does this Scala Perl/Python architecture make sense
| 4,892,391 |
2 | 3 | 0 | 0 | 2 | 1 | 0 | 0 |
I am a 3rd year CS engineering student, I have done some basic programming in languages like C,C++,Java,Shell,Perl,PHP,Ruby on Rails, Python. But now I wanted to settle for one language, so I thought of finally mastering one scripting language and other compiled one. So I decided to stick with C++ and Python. Can someone suggest me, would these be sufficient for any kind of programming, or for web designing I should stick to ROR?
| 0 |
c++,python,ruby-on-rails
|
2011-02-04T09:22:00.000
| 0 | 4,896,361 |
Language should be a means to an end. Pick a project you want to work on, then figure out what you will need to know to get the job done. It's very difficult to get any language-learning to stick without some practical application.
And "knowing a language" is not particularly difficult or useful. Knowing how to use most of the important libraries and platforms associated with a language is usually much more time-intensive and useful.
As far as picking a project if you can't think of one, maybe try for something on a mobile platform -- Android / iOS / Windows Phone. These are generally useful for learning not only a language, but a complete set of tools to take an idea from concept to published.
| 0 | 436 | false | 1 | 1 |
Which programming language to choose?
| 4,896,404 |
2 | 3 | 0 | 0 | 2 | 1 | 0 | 0 |
I am a 3rd year CS engineering student, I have done some basic programming in languages like C,C++,Java,Shell,Perl,PHP,Ruby on Rails, Python. But now I wanted to settle for one language, so I thought of finally mastering one scripting language and other compiled one. So I decided to stick with C++ and Python. Can someone suggest me, would these be sufficient for any kind of programming, or for web designing I should stick to ROR?
| 0 |
c++,python,ruby-on-rails
|
2011-02-04T09:22:00.000
| 0 | 4,896,361 |
Presently ROR is high in demand for web. As a professional i'll suggest to learn ROR.
| 0 | 436 | false | 1 | 1 |
Which programming language to choose?
| 4,896,389 |
1 | 7 | 0 | 1 | 10 | 0 | 0.028564 | 1 |
I already know there are ssh modules for Python, that's not for what I'm looking for.
What I want to have is an python script to do the following:
> connect to an [ input by user ] SSH host
> connect using the credentials [ provided by the user ]
> run command on the SSH host [ telnet to [host - input by user ]
> Select menu item in the telnet session
Thanks in advance,
Best regards,
| 0 |
python,automation,ssh,telnet
|
2011-02-04T10:12:00.000
| 1 | 4,896,785 |
There are many libraries to do that.
Subprocess
Pexpect
Paramiko (Mostly used)
Fabric
Exscript
You can check their documentation for the implementation.
| 0 | 74,237 | false | 0 | 1 |
Python script - connect to SSH and run command
| 39,664,919 |
1 | 1 | 1 | 1 | 0 | 0 | 0.197375 | 0 |
i've built a com component which utilizes libxml2 python bindings , the build is successfull but when i try to register the component i get "specified module could not be found , unable to load python dll" this is the error i get when the component is built using the bundle files option set as 1
if i build the component with bundle files set as 3 ,then i get a different error saying that the component was loaded but the call to DllRegisterServer Failed with error code 80040201
if the libxml2 import is removed all works fine.
any help wold be simply great.
thanks
| 0 |
python,com
|
2011-02-04T14:33:00.000
| 0 | 4,899,158 |
Most likely, regsvr32.exe which registers you COM component couldn't find a DLL that your COM component needs.
I'm not familiar with Python COM components but is there some way you can run depends.exe on it? This is the usual way to track down binary dependency problems.
| 0 | 240 | false | 0 | 1 |
python com component does not register when using libxml2 on win7
| 4,899,486 |
1 | 3 | 0 | 1 | 1 | 0 | 0.066568 | 0 |
I have a PHP/mySQL site that is no longer going to get any new content added. But I'd like to keep what I do have as an archive and keep it online. Ideally I'd like to convert it to a static site so that it no longer requires a database.
If anyone else has gone through this process, are there any tools, scripts, or methodologies that can automate this or at least make this easier? I'd want to be able to do things like make sure that all the links still work (so they'd have to somehow be converted to correctly point to the new static versions), things like that.
I have ssh access to the server in question. I'm relatively comfortable with both PHP and Python so tools using those languages would be ideal.
Note: there are two basic reasons I'm doing this:
cost, as it's much cheaper to host just a collection of static files than a dynamic website (I'm using NearlyFreeSpeech and with the bandwidth I'm using I estimate my costs would go down to well under $1/month).
spammers have somehow found my site and keep signing up for accounts (at which point, they're blocked from making comments anyway, but it's still annoying).
| 0 |
php,python,dynamic,static,archive
|
2011-02-04T17:30:00.000
| 0 | 4,901,039 |
Using PHP you could write a simple script that would do this:
Save current page.
Follow links from that page and saving those pages (and for each page repeat from 1).
Replace URLs on current page with those leading to saved pages.
| 0 | 1,156 | false | 1 | 1 |
Converting a dynamic PHP/mySQL website to an archived HTML version?
| 4,901,187 |
2 | 4 | 0 | 2 | 6 | 0 | 0.099668 | 0 |
I am thinking in starting a personal pet web project to experiment with different things and extend my knowledge.
I use Java a lot at work (for web applications :D) and was thinking in making my own in Python since I kinda like this language but never passed the simple scripts stages.
I want to step up a gear regarding Python (using 2.6.5) and don't know what to expect or what framework to choose from: Django, Pylons, web2py etc.
I also don't know how much these frameworks will offer me and how much will I have to write from scratch.
I could use a comparison with Java if somebody can provide me with. I'm thinking at filter functionalities such as sitemesh, custom tags like JSTL; In Python, can I write clean pages of HTML with tags in them or write a lot of print statements (something like servlets did in Java etc?
I don't know exactly how to phrase this question.
I actually need a presentation of how web development is performed in Python, at what level, and what the web frameworks bring to the table.
Can you share from your experience?
TIA!
| 0 |
java,python,templates,web-frameworks
|
2011-02-05T19:57:00.000
| 0 | 4,909,306 |
It may sound strange, but there's no need to know "how web development is performed in Python" to start doing it.
In fact, working with language/framework/etc is a single most reliable way to get understanding of it. You won't gain a lot from one-page summaries.
Also, comparing it with Java isn't likely to help. There's no point in doing "Java-style development in Python". If you want to benefit, you'll need to clear your mind and do everything "Python-way".
As to what Python framework to choose, Django seems like like a good starting point. It's very popular, which means you won't be left without tutorials/documentation/help.
PS Short version: just do it.
| 0 | 5,940 | false | 1 | 1 |
Python web frameworks vs Java web frameworks (how is web development in Python done?)
| 4,909,342 |
2 | 4 | 0 | 3 | 6 | 0 | 0.148885 | 0 |
I am thinking in starting a personal pet web project to experiment with different things and extend my knowledge.
I use Java a lot at work (for web applications :D) and was thinking in making my own in Python since I kinda like this language but never passed the simple scripts stages.
I want to step up a gear regarding Python (using 2.6.5) and don't know what to expect or what framework to choose from: Django, Pylons, web2py etc.
I also don't know how much these frameworks will offer me and how much will I have to write from scratch.
I could use a comparison with Java if somebody can provide me with. I'm thinking at filter functionalities such as sitemesh, custom tags like JSTL; In Python, can I write clean pages of HTML with tags in them or write a lot of print statements (something like servlets did in Java etc?
I don't know exactly how to phrase this question.
I actually need a presentation of how web development is performed in Python, at what level, and what the web frameworks bring to the table.
Can you share from your experience?
TIA!
| 0 |
java,python,templates,web-frameworks
|
2011-02-05T19:57:00.000
| 0 | 4,909,306 |
hi try bottle python framework (bottle.paws.de / bottlepy.org) its really nice to use blistering fast and gets out of your way + the best thing about it is that its one single file to import, i recently migrated from PHP and i have to tell you am so ... loving it!
| 0 | 5,940 | false | 1 | 1 |
Python web frameworks vs Java web frameworks (how is web development in Python done?)
| 6,586,407 |
1 | 1 | 0 | 1 | 1 | 0 | 1.2 | 0 |
I want to run php or python scripts from eclipse that will create folders and files and give them content. I think I know what to write for the php or python code but I am having trouble on what I need to do in eclipse to run my script. I would also like to provide my script with arguments such as folder names through a prompt on the eclipse side.
I think I have to do something from Run-> External Tools -> External Tools Configuration.
Please Help, Thank you.
| 0 |
php,python,eclipse,configuration
|
2011-02-05T23:54:00.000
| 0 | 4,910,541 |
you shouldn't have to do anything to eclipse, or any editor, if php\python is installed you can call them from the command line.
| 0 | 132 | true | 0 | 1 |
configurations eclipse
| 4,910,592 |
2 | 2 | 0 | 1 | 1 | 0 | 0.099668 | 1 |
I'm currently writing a set of unit tests for a Python microblogging library, and following advice received here have begun to use mock objects to return data as if from the service (identi.ca in this case).
However, surely by mocking httplib2 - the module I am using to request data - I am tying the unit tests to a specific implementation of my library, and removing the ability for them to function after refactoring (which is obviously one primary benefit of unit testing in the firt place).
Is there a best of both worlds scenario? The only one I can think of is to set up a microblogging server to use only for testing, but this would clearly be a large amount of work.
| 0 |
python,unit-testing
|
2011-02-06T16:35:00.000
| 0 | 4,914,582 |
Not sure what your problem is. The mock class is part of the tests, conceptually at least. It is ok for the tests to depend on particular behaviour of the mock objects that they inject into the code being tested. Of course the injection itself should be shared across unit tests, so that it is easy to change the mockup implementation.
| 0 | 223 | false | 0 | 1 |
Using mock objects without tying down unit tests
| 4,914,696 |
2 | 2 | 0 | 1 | 1 | 0 | 1.2 | 1 |
I'm currently writing a set of unit tests for a Python microblogging library, and following advice received here have begun to use mock objects to return data as if from the service (identi.ca in this case).
However, surely by mocking httplib2 - the module I am using to request data - I am tying the unit tests to a specific implementation of my library, and removing the ability for them to function after refactoring (which is obviously one primary benefit of unit testing in the firt place).
Is there a best of both worlds scenario? The only one I can think of is to set up a microblogging server to use only for testing, but this would clearly be a large amount of work.
| 0 |
python,unit-testing
|
2011-02-06T16:35:00.000
| 0 | 4,914,582 |
You are right that if you refactor your library to use something other than httplib2, then your unit tests will break. That isn't such a horrible dependency, since when that time comes it will be a simple matter to change your tests to mock out the new library.
If you want to avoid that, then write a very minimal wrapper around httplib2, and your tests can mock that. Then if you ever shift away from httplib2, you only have to change your wrapper. But notice the number of lines you have to change is the same either way, all that changes is whether they are in "test code" or "non-test code".
| 0 | 223 | true | 0 | 1 |
Using mock objects without tying down unit tests
| 4,915,281 |
3 | 3 | 0 | 2 | 2 | 1 | 0.132549 | 0 |
I have a couple versions of python on my box. My app uses python 2.7 which is found in /usr/local/bin/python. Apache seems to be using an earlier version in /usr/bin/python. How can I configure Apache to use a later version of Python for my app?
| 0 |
python,apache
|
2011-02-07T22:59:00.000
| 1 | 4,927,688 |
To use with Python 3, you need to install the right mod_wsgi for python 3.
On Debian or Ubuntu : sudo apt-get install libapache2-mod-wsgi-py3.
For older versions of Python, when installing mod_wsgi, type : ./configure --with-python=/usr/local/bin/python2.5 for version 2.5 for instance.
| 0 | 2,129 | false | 0 | 1 |
Apache Config - Multiple python versions
| 29,809,235 |
3 | 3 | 0 | 0 | 2 | 1 | 0 | 0 |
I have a couple versions of python on my box. My app uses python 2.7 which is found in /usr/local/bin/python. Apache seems to be using an earlier version in /usr/bin/python. How can I configure Apache to use a later version of Python for my app?
| 0 |
python,apache
|
2011-02-07T22:59:00.000
| 1 | 4,927,688 |
I could be mistaking, but whatever user apache is started with has a profile which likely has the search path in it. You could change the search path to search /usr/local/bin before /usr/bin, though this is not an ideal approach. Whatever default shell is set for the account used by Apache, just check that you have an rc-file for that shell, and if not, create one.
| 0 | 2,129 | false | 0 | 1 |
Apache Config - Multiple python versions
| 4,928,096 |
3 | 3 | 0 | 1 | 2 | 1 | 1.2 | 0 |
I have a couple versions of python on my box. My app uses python 2.7 which is found in /usr/local/bin/python. Apache seems to be using an earlier version in /usr/bin/python. How can I configure Apache to use a later version of Python for my app?
| 0 |
python,apache
|
2011-02-07T22:59:00.000
| 1 | 4,927,688 |
You can't. Either rebuild mod_wsgi against the other version of Python, or change the shebang line in your CGI scripts to the other executable.
| 0 | 2,129 | true | 0 | 1 |
Apache Config - Multiple python versions
| 4,927,767 |
3 | 4 | 0 | 275 | 141 | 1 | 1 | 0 |
Every time I read either WSGI or CGI I cringe. I've tried reading on it before but nothing really has stuck.
What is it really in plain English?
Does it just pipe requests to a terminal and redirect the output?
| 0 |
python,cgi,wsgi
|
2011-02-08T04:42:00.000
| 0 | 4,929,626 |
From a totally step-back point of view, Blankman, here is my "Intro Page" for Web Server Gateway Interface:
PART ONE: WEB SERVERS
Web servers serve up responses. They sit around, waiting patiently, and then with no warning at all, suddenly:
a client process sends a request. The client process could be a web server, a bot, a mobile app, whatever. It is simply "the client"
the web server receives this request
deliberate mumble various things happen (see below)
The web server sends back something to the client
web server sits around again
Web servers (at least, the better ones) are VERY good at this. They scale up and down processing depending on demand, they reliably hold conversations with the flakiest of clients over really cruddy networks, and we never really have to worry about it. They just keep on serving.
This is my point: web servers are just that: servers. They know nothing about content, nothing about users, nothing in fact other than how to wait a lot and reply reliably.
Your choice of web server should reflect your delivery preference, not your software. Your web server should be in charge of serving, not processing or logical stuff.
PART TWO: (PYTHON) SOFTWARE
Software does not sit around. Software only exists at execution time. Software is not terribly accommodating when it comes to unexpected changes in its environment (files not being where it expects, parameters being renamed etc). Although optimisation should be a central tenet of your design (of course), software itself does not optimise. Developers optimise. Software executes. Software does all the stuff in the 'deliberate mumble' section above. Could be anything.
Your choice or design of software should reflect your application, your choice of functionality, and not your choice of web server.
This is where the traditional method of "compiling in" languages to web servers becomes painful. You end up putting code in your application to cope with the physical server environment or, at least, being forced to choose an appropriate 'wrapper' library to include at runtime, to give the illusion of uniformity across web servers.
SO WHAT IS WSGI?
So, at last, what is WSGI? WSGI is a set of rules, written in two halves. They are written in such a way that they can be integrated into any environment that welcomes integration.
The first part, written for the web server side, says "OK, if you want to deal with a WSGI application, here's how the software will be thinking when it loads. Here are the things you must make available to the application, and here is the interface (layout) that you can expect every application to have. Moreover, if anything goes wrong, here's how the app will be thinking and how you can expect it to behave."
The second part, written for the Python application software, says "OK, if you want to deal with a WSGI server, here's how the server will be thinking when it contacts you. Here are the things you must make available to the server, and here is the interface (layout) that you can expect every server to have. Moreover, if anything goes wrong, here's how you should behave and here's what you should tell the server."
So there you have it - servers will be servers and software will be software, and here's a way they can get along just great without one having to make any allowances for the specifics of the other. This is WSGI.
mod_wsgi, on the other hand, is a plugin for Apache that lets it talk to WSGI-compliant software, in other words, mod_wsgi is an implementation - in Apache - of the rules of part one of the rule book above.
As for CGI.... ask someone else :-)
| 0 | 27,805 | false | 0 | 1 |
What are WSGI and CGI in plain English?
| 5,120,610 |
3 | 4 | 0 | 22 | 141 | 1 | 1 | 0 |
Every time I read either WSGI or CGI I cringe. I've tried reading on it before but nothing really has stuck.
What is it really in plain English?
Does it just pipe requests to a terminal and redirect the output?
| 0 |
python,cgi,wsgi
|
2011-02-08T04:42:00.000
| 0 | 4,929,626 |
Both CGI and WSGI define standard interfaces that programs can use to handle web requests. The CGI interface is at a lower level than WSGI, and involves the server setting up environment variables containing the data from the HTTP request, with the program returning something formatted pretty much like a bare HTTP server response.
WSGI, on the other hand, is a Python-specific, slightly higher-level interface that allows programmers to write applications that are server-agnostic and which can be wrapped in other WSGI applications (middleware).
| 0 | 27,805 | false | 0 | 1 |
What are WSGI and CGI in plain English?
| 4,929,678 |
3 | 4 | 0 | 68 | 141 | 1 | 1.2 | 0 |
Every time I read either WSGI or CGI I cringe. I've tried reading on it before but nothing really has stuck.
What is it really in plain English?
Does it just pipe requests to a terminal and redirect the output?
| 0 |
python,cgi,wsgi
|
2011-02-08T04:42:00.000
| 0 | 4,929,626 |
WSGI runs the Python interpreter on web server start, either as part of the web server process (embedded mode) or as a separate process (daemon mode), and loads the script into it. Each request results in a specific function in the script being called, with the request environment passed as arguments to the function.
CGI runs the script as a separate process each request and uses environment variables, stdin, and stdout to "communicate" with it.
| 0 | 27,805 | true | 0 | 1 |
What are WSGI and CGI in plain English?
| 4,929,656 |
3 | 3 | 0 | 0 | 0 | 0 | 1.2 | 0 |
I cant seem to find a reliable asymmetric encryption solution to secure data between a python based server application and a client over an open data channel.
I need some way for my client to prevent a man in the middle attack over an open data channel, my current exchange has me sending my clients a token they use to verify they are talking to my server application by checking the token is valid with a php script on my site.
This is far from ideal and could easily be compromised by waiting to be sent the token and passing it off to another user.
I have tried as3crypto's rsa encryption but it is an old implementation that is not supported by many libraries as well as having a known vulnerability.
I would really like a solution that lets me hard code public/private keys into both the client and server to prevent something like this from happening.
| 0 |
python,actionscript,cryptography,token,encryption-asymmetric
|
2011-02-08T08:53:00.000
| 0 | 4,931,126 |
After doing some research I have decided to code the part of rsa I need from scratch.
I found some python code that will generate raw integer keys of any length and looked up how the rsa algorithm works.
T^P = X (mod R) to encrypt
X^Q = T (mod R) to decrypt
Where T is the starting data, X is the ending data, P is the public half of the key, Q is the private half of the key, and R is the shared part of the key (all integers).
Data will have a nonice whenever possible to prevent replay attacks and the message as a whole will be converted to a long integer to prevent traditional bit by bit cryptanalysis.
| 0 | 191 | true | 1 | 1 |
Actionscript Three Asymmetric Encryption
| 4,999,135 |
3 | 3 | 0 | 0 | 0 | 0 | 0 | 0 |
I cant seem to find a reliable asymmetric encryption solution to secure data between a python based server application and a client over an open data channel.
I need some way for my client to prevent a man in the middle attack over an open data channel, my current exchange has me sending my clients a token they use to verify they are talking to my server application by checking the token is valid with a php script on my site.
This is far from ideal and could easily be compromised by waiting to be sent the token and passing it off to another user.
I have tried as3crypto's rsa encryption but it is an old implementation that is not supported by many libraries as well as having a known vulnerability.
I would really like a solution that lets me hard code public/private keys into both the client and server to prevent something like this from happening.
| 0 |
python,actionscript,cryptography,token,encryption-asymmetric
|
2011-02-08T08:53:00.000
| 0 | 4,931,126 |
Hardcoding they public keys won't help you, if someone really plans an attack, because the SWF itself is transfered over an unsafe channel, thus the keys can be exchanged just as if they were transmitted individually.
There is basically nothing you can do to prevent man in the middle attacks, you can only make them harder. I think HTTPS is about the best you can get and it's also a fairly easy solution.
| 0 | 191 | false | 1 | 1 |
Actionscript Three Asymmetric Encryption
| 4,947,928 |
3 | 3 | 0 | 0 | 0 | 0 | 0 | 0 |
I cant seem to find a reliable asymmetric encryption solution to secure data between a python based server application and a client over an open data channel.
I need some way for my client to prevent a man in the middle attack over an open data channel, my current exchange has me sending my clients a token they use to verify they are talking to my server application by checking the token is valid with a php script on my site.
This is far from ideal and could easily be compromised by waiting to be sent the token and passing it off to another user.
I have tried as3crypto's rsa encryption but it is an old implementation that is not supported by many libraries as well as having a known vulnerability.
I would really like a solution that lets me hard code public/private keys into both the client and server to prevent something like this from happening.
| 0 |
python,actionscript,cryptography,token,encryption-asymmetric
|
2011-02-08T08:53:00.000
| 0 | 4,931,126 |
Since decompiling swf content is not a major problem for experienced hackers, I would strongly advise against hardcoding keys. Have you thought about using SSL at all?
| 0 | 191 | false | 1 | 1 |
Actionscript Three Asymmetric Encryption
| 4,947,858 |
1 | 1 | 0 | 1 | 0 | 0 | 1.2 | 0 |
I'm using PyBluez on Ubuntu 10.10. I would like to know how is possible to change the bluetooth name of the local device in software. I couldn't find any command related..
| 0 |
python,bluetooth,ubuntu-10.10
|
2011-02-08T09:10:00.000
| 1 | 4,931,244 |
Invoke org.bluez.Adapter.SetProperty(u'Name', u'New name here') in the /org/bluez/<pid>/<device> object path on the org.bluez D-Bus bus.
| 0 | 1,096 | true | 0 | 1 |
Change Bluetooth name Python
| 4,931,264 |
1 | 1 | 0 | 7 | 4 | 0 | 1.2 | 0 |
I'm looking for a good way to estimate the power of a signal (regularly sampled say at 10 kHz) vs. time at just one frequency (say 50 Hz). I could calculate the spectrogram, and then take a slice of it at the target frequency. This seems inefficient though, since I only care about the power at one frequency vs. time. I realize that the power at exactly one frequency is zero (in the limit), I'd like to calculate the power of the signal within a small frequency interval around the target frequency.
My current "solution" is to use Matplotlib's mlab.specgram() function which returns a 2d array of power, and I just slice it. I'm not satisified with this though because I don't totally trust the mab.specgram() function as it takes drastically different amounts of time to compute the spectrogram on different signals (even if they are the same length).
| 0 |
python,matplotlib,signal-processing,scientific-computing
|
2011-02-10T04:06:00.000
| 0 | 4,953,250 |
There's a ton of ways of doing this. One crude but effective way is to apply a bandpass filter (at 50Hz), thereby eliminating all other signals, and then calculate the RMS power of the last N samples.
Another is you can do a windowed FFT, but not actually FFT - just calculate the bin you want. The window can be whatever you want (e.g Kaiser with alpha 8). The DFT of a single bin is just the sum of products of the signal with e^(i*n*w) (where w is 50Hz at your sampling rate, and n the iterator).
There's probably simpler ways than that. It depends on what you're trying to be resilient to, how fast the signal moves, and whether you expect noise or other signals in the mix. If you're not trying to pick a signal out of a cacophony of others, you don't have to go to great lengths.
| 0 | 1,962 | true | 0 | 1 |
how to estimate the (power of a signal at a given frequency) vs. time in python
| 4,953,341 |
1 | 1 | 0 | 1 | 1 | 0 | 1.2 | 0 |
I have a custom module that's basically a thin wrapper around a database connection with cx_Oracle. I'd like to re-use this module on computers with both the unicode version of cx_Oracle installed, and with the non-unicode version.
To do this, I need to "detect" the version installed. I could "try" making a connection using a string connection descriptor; and if I get a TypeError back, then assume it's the unicode version installed. This just seems a bit kludgy.
Is there a better/preferred way of doing this?
Thanks.
| 0 |
python,cx-oracle
|
2011-02-10T19:32:00.000
| 0 | 4,961,707 |
Using try ... except is a perfectly suitable way to do this kind of detection. The same technique is used to write portable apps using SQLITE that will work on newer 2.7 Python with SQLITE in the library and older 2.4 where SQLITE was an addon module with a more cryptic name.
| 0 | 227 | true | 0 | 1 |
Is this the preferred way to detect if the unicode or non-unicode version of cx_oracle was installed?
| 5,087,119 |
1 | 4 | 0 | 0 | 0 | 1 | 0 | 0 |
I apologize for not giving this question a better title; the reason that I am posting it is that I don't even have the correct terminology to know what I am looking for.
I have defined a class with an attribute 'spam':
def SpamClass(object):
def __init__(self, arg):
self.spam = arg
def __str__(self):
return self.spam
I want to create a (sub/sibling?)class that has exactly the same functionality, but with an attribute named 'eggs' instead of 'spam':
def EggsClass(object):
def __init__(self, arg):
self.eggs = arg
def __str__(self):
return self.eggs
To generalize, how do I create functionally-identical classes with arbitrary attribute names? When the class has complicated behavior, it seems silly to duplicate code.
Update: I agree that this smells like bad design. To clarify, I'm not trying to solve a particular problem in this stupid way. I just want to know how to arbitrarily name the (non-magic) contents of an object's __dict__ while preserving functionality. Consider something like the keys() method for dict-like objects. People create various classes with keys() methods that behave according to convention, and the naming convention is a Good Thing. But the name is arbitrary. How can I make a class with a spam() method that exactly replaces keys() without manually substituting /keys/spam/ in the source?
Overloading __getattr__ and friends to reference the generic attribute seems inelegant and brittle to me. If a subclass reimplements these methods, it must accommodate this behavior. I would rather have it appear to the user that there is simply a base class with a named attribute that can be accessed naively.
Actually, I can think of a plausible use case. Suppose that you want a mixin class that confers a special attribute and some closely related methods that manipulate or depend upon this attribute. A user may want to name this special attribute differently for different classes (to match names in the real-world problem domain or to avoid name collisions) while reusing the underlying behavior.
| 0 |
python,attributes,introspection,metaclass
|
2011-02-11T07:16:00.000
| 0 | 4,966,509 |
To create attributes during runtime, just add them in self.__dict__['foo'] = 'I'm foo' in the class code.
| 0 | 722 | false | 0 | 1 |
creating Python classes with arbitrarily substituted attribute name
| 4,967,128 |
1 | 2 | 0 | 2 | 1 | 0 | 0.197375 | 0 |
Hi
I use twisted library to connect to FTP server but I have problem with filename encoding.
I receive 'Illusion-N\xf3z.txt' so its not unicode. Is there any FTP command to force specific encoding?
Thanks in advance!
MK
| 0 |
python,encoding,ftp,twisted
|
2011-02-11T08:12:00.000
| 1 | 4,966,856 |
FTP ignores encodings; as long as a filename does not contain a '\0' (null character) and '/' (slash) separates directories, it happily accepts anything.
Do your own decoding and encoding of the filenames. It is quite probable that the encoding used in your example is "cp1252", which is the “Windows Western” or something like that.
In your case, when you receive 'Illusion-N\xf3z.txt', convert it to Unicode by 'Illusion-N\xf3z.txt'.decode('cp1252').
| 0 | 3,170 | false | 0 | 1 |
FTP filename encoding
| 5,210,013 |
3 | 4 | 0 | 5 | 1 | 1 | 1.2 | 0 |
Is there a difference (in terms of execution time) between implementing a function in Python and implementing it in C and then calling it from Python? If so, why?
| 0 |
python,c,compilation
|
2011-02-11T11:00:00.000
| 0 | 4,968,235 |
Python (at least the "standard" CPython implementation) never actually compiles to native machine code; it compiles to bytecode which is then interpreted. So a C function which is in fact compiled to machine code will run faster; the question is whether it will make a relevant difference. So what's the actual problem you're trying to solve?
| 0 | 330 | true | 0 | 1 |
Implementing a function in Python vs C
| 4,968,256 |
3 | 4 | 0 | 0 | 1 | 1 | 0 | 0 |
Is there a difference (in terms of execution time) between implementing a function in Python and implementing it in C and then calling it from Python? If so, why?
| 0 |
python,c,compilation
|
2011-02-11T11:00:00.000
| 0 | 4,968,235 |
Typically, a function written in C will be substantially faster that the Python equivalent. It is also much more difficult to integrate, since it involves:
compiling C code that #includes the Python headers and exposes appropriate wrapper code so that it is callable from Python;
linking against the correct Python libraries;
deploying the resulting shared library to the appropriate location, so that your Python code can import it.
You would want to be very certain that the benefits outweigh the costs before trying this, which means this should only be reserved for performance-critical sections of your code that you simply can't make fast enough with pure Python.
If you really need to go down this path, Boost.Python can make the task much less painful.
| 0 | 330 | false | 0 | 1 |
Implementing a function in Python vs C
| 4,968,264 |
3 | 4 | 0 | 1 | 1 | 1 | 0.049958 | 0 |
Is there a difference (in terms of execution time) between implementing a function in Python and implementing it in C and then calling it from Python? If so, why?
| 0 |
python,c,compilation
|
2011-02-11T11:00:00.000
| 0 | 4,968,235 |
If I understand and restate your question properly, you are asking, if wrapping python over a c executable be anyway faster than a pure python module itself? The answer to it is, it depends upon the executable and the kind of task you are performing.
There are a set of modules in Python that are written using Python C-API's. Performance of those would be comparable to wrapping a C executable
On the other hand, wrapping c program would be faster than pure python both implementing the same functionality with a sane logic. Compare difflib usage vs wrapping subprocess over diff.
| 0 | 330 | false | 0 | 1 |
Implementing a function in Python vs C
| 4,968,320 |
1 | 2 | 0 | 3 | 2 | 1 | 1.2 | 0 |
I have to use some legacy .pyc modules (with no source) but I'm also forced to use python in optimized mode (python -O): so, when trying to import those modules, I get an import error (as python looks for .py or .pyo files).
Is there a way to make it use pyc modules as well? Or to convert .pyc into .pyo?
| 0 |
python,import,compiler-optimization,pyc
|
2011-02-11T15:49:00.000
| 0 | 4,971,066 |
One way to "convert" them is simply renaming them. Of course they won't be optimised, but at least you can use them.
| 0 | 666 | true | 0 | 1 |
Make Python import .pyc when run in optimized mode
| 4,971,101 |
1 | 4 | 0 | -4 | 8 | 0 | -1 | 0 |
Is it possible to find out the process id of the process which has caused some signal. In my scenario, I have multiple children of a process running, and I want to know which one of them sent the signal.
| 0 |
python,signals
|
2011-02-11T21:16:00.000
| 0 | 4,974,140 |
I believe it is not possible - the OS just does not pass this information to the target process.
| 0 | 4,214 | false | 0 | 1 |
Get pid of the process which has triggered some signal
| 4,974,239 |
2 | 4 | 0 | 2 | 1 | 0 | 1.2 | 0 |
I've been learning python for use in ArcGIS and some other non-web applications. However, now that I've taken on building a personal website I am interested in using it for web development (as it is the only scripting language I currently know).
I've noticed that there are a lot of these things called "frameworks", such as Django. From what I understand they are just a collection of packages to save you from re-inventing the wheel but I don't really know how they work.
Furthermore, I do not like GUIs, if I need a framework I would like to find one that could be used through a terminal, starts out simple and can be scaled for more complexity when I'm ready. Any advice or ideas on frameworks and why I would want to use one?
| 0 |
python,web,web-frameworks,web-scripting
|
2011-02-12T21:30:00.000
| 0 | 4,980,756 |
The Python web frameworks have nothing to do with GUIs, and can all be used via the terminal.
The benefits of a framework, as you say, are all to do with making your life easier by supplying the components you need to build a website: the main ones are database interaction through an ORM, a templating system, and URL routing. On top of that, the big frameworks also included optional extras like user authentication, administration interface, and so on.
Personally I like Django, but your mileage may vary: I would say, though, that whatever you do with Python and the web will require some sort of framework, even if it's one of the absolute minimal ones like Flask which basically do just the routing part. There's simply no point in writing all this stuff from scratch when it's been done for you.
| 0 | 553 | true | 1 | 1 |
I'm learning python and am interested in using it for web-scripting. What frameworkes are out there and do I need one?
| 4,980,831 |
2 | 4 | 0 | 0 | 1 | 0 | 0 | 0 |
I've been learning python for use in ArcGIS and some other non-web applications. However, now that I've taken on building a personal website I am interested in using it for web development (as it is the only scripting language I currently know).
I've noticed that there are a lot of these things called "frameworks", such as Django. From what I understand they are just a collection of packages to save you from re-inventing the wheel but I don't really know how they work.
Furthermore, I do not like GUIs, if I need a framework I would like to find one that could be used through a terminal, starts out simple and can be scaled for more complexity when I'm ready. Any advice or ideas on frameworks and why I would want to use one?
| 0 |
python,web,web-frameworks,web-scripting
|
2011-02-12T21:30:00.000
| 0 | 4,980,756 |
Personnally, I don't use any framework, I write either from scratch on BaseHTTPServer, or using WSGI (with mod_wsgi).
It is a bit long to write the skeleton, but I think it is faster (I mean at runtime), there is less constraints, and there is lesser to learn.
| 0 | 553 | false | 1 | 1 |
I'm learning python and am interested in using it for web-scripting. What frameworkes are out there and do I need one?
| 4,981,185 |
3 | 6 | 0 | 0 | 0 | 0 | 0 | 0 |
I want my program by default to stdout, but give the option of writing it to a file. Should I create my own print function and call that testing that there is an output file or is there a better way? That seems inefficient to me, but every way I can think of calls an additional if test for every print call. I know this really doesn't matter in the long run probably, at least of this script, but I'm just trying to learn good habits.
| 0 |
python,redirect
|
2011-02-12T23:51:00.000
| 0 | 4,981,444 |
I recommend you using the logging module and logging.handlers... stream, output files, etc..
| 0 | 222 | false | 0 | 1 |
What's the best way to handle output redirection?
| 4,981,494 |
3 | 6 | 0 | 2 | 0 | 0 | 1.2 | 0 |
I want my program by default to stdout, but give the option of writing it to a file. Should I create my own print function and call that testing that there is an output file or is there a better way? That seems inefficient to me, but every way I can think of calls an additional if test for every print call. I know this really doesn't matter in the long run probably, at least of this script, but I'm just trying to learn good habits.
| 0 |
python,redirect
|
2011-02-12T23:51:00.000
| 0 | 4,981,444 |
Write to a file object, and when the program starts either have that object point to sys.stdout or to a file specified by the user.
Mark Byers' answer is more unix-like, where most command line tools just use stdin and stdout and let the user do redirection as they see fit.
| 0 | 222 | true | 0 | 1 |
What's the best way to handle output redirection?
| 4,981,549 |
3 | 6 | 0 | -1 | 0 | 0 | -0.033321 | 0 |
I want my program by default to stdout, but give the option of writing it to a file. Should I create my own print function and call that testing that there is an output file or is there a better way? That seems inefficient to me, but every way I can think of calls an additional if test for every print call. I know this really doesn't matter in the long run probably, at least of this script, but I'm just trying to learn good habits.
| 0 |
python,redirect
|
2011-02-12T23:51:00.000
| 0 | 4,981,444 |
My reaction would be to output to a temp file, then either dump that to stdio, or move it to where they requested.
| 0 | 222 | false | 0 | 1 |
What's the best way to handle output redirection?
| 4,981,465 |
1 | 1 | 0 | 12 | 5 | 0 | 1.2 | 0 |
I have some problems whith IntelliJ IDEA Python plugin.
I've got a Java project with a few modules. And I want to add one module for Python tools-scripts which I use to generate some files.
I downloaded and installed Python plugin (version 2.6.6.) for my IDEA (10.0.2 Ultimate). Then I added Python SDK to the project and created new Python module. Then I added /src dir to this new module.
When I right-click on this module, I have a context menu item New -> Python file. I can add my .py file to my module. Also I can create Python Run/Debug Configuration. And IDEA can launch my script. But IDEA doesn't highlight Python syntax. It marks Python module with Python icon, but my Python file is marked as a text file.
I have inspected all settings, but I failed solving this problem. /src is marked as 'Source folder' in 'Project Structure' dialog.
| 0 |
python,intellij-idea
|
2011-02-13T10:52:00.000
| 0 | 4,983,715 |
See Settings | File Types, verify that .py extension is associated with Python file type.
| 0 | 6,090 | true | 0 | 1 |
IntelliJ IDEA: Python plugin does not highlight Python code
| 4,984,030 |
1 | 2 | 0 | 0 | 0 | 1 | 0 | 0 |
Many applications include a python interpreter, so now when I try to run a program, Subversion's 2.5 interpreter is used to execute it.
I've already changed environment path order, putting subversion's last.
Now when I run python from command line, the 2.7 is run, but when I pass the script's filename, version 2.5 seems to be running it, as a few exceptions reveal the path.
So specifically, python 2.7 tries to imports module from subversions path.
| 0 |
python,path,interpreter
|
2011-02-13T12:27:00.000
| 1 | 4,984,124 |
If you are having problems with PATH in windows, set the one you want to use at the start of the path variable. Plus, you might want to use User variables instead of system ones.
But I don't know if that answers your question because you didn't really ask anything.
| 0 | 453 | false | 0 | 1 |
Python interpreter path search order on windows
| 4,984,297 |
1 | 12 | 0 | 0 | 300 | 1 | 0 | 0 |
What do I have to do in Python to figure out which encoding a string has?
| 0 |
python,unicode,encoding,utf-8
|
2011-02-13T22:27:00.000
| 0 | 4,987,327 |
For py2/py3 compatibility simply use
import six
if isinstance(obj, six.text_type)
| 0 | 424,066 | false | 0 | 1 |
How do I check if a string is unicode or ascii?
| 50,565,892 |
1 | 2 | 0 | 0 | 6 | 0 | 0 | 1 |
Trying to achieve:
same firefox profile throughout tests
Problem:
Tests are spread over 30 different files, instantiating a selenium object, and thus creating a firefox profile, in the first test won't persist to the following test because the objects die once script ends IIRC
Can't specify profile because I'm writing a test suite supposed to be run on different machines
Possible solutions:
Creating a selenium object in some common code that stays in memory throughout the tests. I am running each test by spawning a new python process and waiting for it to end. I am unsure how to send objects in memory to a new python object.
Any help is appreciated, thanks.
edit: just thought of instead of spawning a child python process to run the test, I just instantiate the test class that selenium IDE generated, removing the setUp and tearDown methods in all 30 tests, instantiating one selenium object in the beginning, then passing said selenium object to every test that's instantiated.
| 0 |
python,selenium
|
2011-02-14T00:04:00.000
| 0 | 4,987,773 |
You can specify the firefox profile while running the server itself. The command would look like
java -jar selenium-server.jar -firefoxProfileTemplate "C:\Selenium\Profiles" where "C:\Selenium\Profiles" would be your path where firefox template files are stored.
| 0 | 1,706 | false | 0 | 1 |
Keeping Firefox profile persistent in multiple Selenium tests without specifying a profile
| 5,481,430 |
1 | 1 | 0 | 1 | 0 | 0 | 1.2 | 0 |
which one is faster:
Using Lattice Multiplication with threads(big numbers) OR
Using common Multiplication with threads(big numbers)
Do you know any source code, to test them?
-----------------EDIT------------------
The theads should be implemented in C, or Java for testing
| 0 |
java,python,c,multiplication
|
2011-02-14T04:31:00.000
| 0 | 4,988,830 |
If I understand you correctly, "lattice multiplication" is different way of doing base-10 multiplication by hand that is supposed to be easier for kids to understand than the classic way. I assume "common multiplication" is the classic way.
So really, I think that the best answer is:
Neither "lattice multiplication" or "common multiplication" are good (efficient) ways of doing multiplication on a computer. For small numbers (up to 2**64), built-in hardware multiplication is better. For large numbers, you are best of breaking the numbers into 8 or 32 bit chunks ...
Multi-threading is unlikely to speed up multiplication unless you have very large numbers. The inherent cost of creating (or recycling) a thread is likely to swamp any theoretical speedup for smaller numbers. And for larger numbers (and larger numbers of threads) you need to worry about the bandwidth of copying the data around.
Note there is a bit of material around on parallel multiplication (Google), but it is mostly in the academic literature ... which maybe says something about how practical it really is for the kind of hardware used today for low and high end computing.
| 1 | 519 | true | 0 | 1 |
Lattice Multiplication with threads, is it more efficient?
| 4,989,194 |
1 | 1 | 1 | 0 | 2 | 1 | 1.2 | 0 |
I'm trying to make a small game that supports Python scripting. I've no problems with using the Python C-API, but I don't know how to ensure that the game will run on a computer with no Python installed.
I know I need pythonXY.dll -- what else is there? When I try to run the program it tells me it cannot find encodings.utf_8. I tried copying the encodings/utf_8.py file in the same directory as my program, but the error still pops up.
| 0 |
python,embed,python-c-api
|
2011-02-14T17:40:00.000
| 0 | 4,995,336 |
You need the encodings/__init__.py file, otherwise encodings is a folder and not a python package.
Chances are that you'll need a lot of stuff from within the python standard library. To make everything just work you'll need to include the entire standard library along with your program.
You can make this a bit better by putting the library in a zip file and adding that to sys.path. Also, you can include only pyc not the original py files.
| 0 | 258 | true | 0 | 1 |
C++ Python embedding: Run on machine with no Python?
| 4,995,435 |
1 | 2 | 0 | 1 | 4 | 1 | 1.2 | 0 |
Eclipse is able to utilize compiled bytecode to enable "magic refactor" functionality--renaming methods, tracing up and down class hierarchies and tracing through method calls.
What technical barriers exist that make this harder to do for languages like Python and Javascript?
| 0 |
javascript,python,eclipse,refactoring,automated-refactoring
|
2011-02-14T18:28:00.000
| 0 | 4,995,842 |
so it turns out that tracing of static information like methods and class hierarchies is perfectly possible in python. PyDev eclipse plugin does it. PyLint plugin attempts to do static analysis even on stuff like dynamic variables by assuming that nothing funky happens at runtime and does a pretty good job.
| 0 | 1,299 | true | 1 | 1 |
why doesn't eclipse-python have magic refactor?
| 5,358,618 |
1 | 1 | 0 | 25 | 42 | 1 | 1.2 | 0 |
No flame wars please. I am admittedly no fan of Java, but I consider the JVM to be a fairly decent and well-optimized virtual machine. It's JIT-enabled and very close to the common denominator of the prevalent CPU architectures. I'd assume that the CPython runtime would be farther from the metal than a corresponding JVM-based runtime.
If my assumptions are correct, could someone explain to me why Jython suffers such a major loss in performance compared to CPython? My initial assumption was that the JVM was simply designed for static languages, and it was difficult to port a dynamic one to it. However, Clojure seems to be an counterexample to that line of argument.
On the other hand, IronPython seems to be doing fine. I believe the the lead developer on both projects were/are the same, so the argument that code design and implementation in one is significantly better than the other does not seem likely.
I can't figure out what the precise reason is; any help will be appreciated.
| 0 |
python,jvm,jython
|
2011-02-15T05:55:00.000
| 0 | 5,000,360 |
Keep in mind that IronPython was started by one of the original Jython devs (Jim Huginin) in an attempt to prove that the .NET CLR was a poor platform for dynamic languages. He ended up proving himself wrong and the core of IronPython eventually became the .NET Dynamic Language Runtime (making other dynamic language implementations on .NET, such as IronRuby, significantly easier to build).
So there's two major points of difference there:
the original .NET CLR devs benefited from additional industry VM experience relative to the early versions of the JVM, allowing them to avoid known problems without backwards compatibility concerns
the same applied for Jim in knowing what traps to avoid based on his Jython experience
Add in a simple lack of development resources devoted to Jython relative to both CPython and IronPython, and Jython development priorities that focused on bringing it up to feature parity with recent versions of Python moreso than speed optimisations and it's quite understandable that Jython would lag when it came to speed.
That said, Jython is similar to both CPython and IronPython, in that the use of better algorithms often trumps poorer performance at microbenchmarks. The JVM/CLR also mean that dropping down to Java or C# for particular components is easier than dropping down into a C extension for CPython (although tools like Cython try to close that gap a bit).
| 0 | 17,795 | true | 1 | 1 |
Why is Jython much slower than CPython, despite the JVM's advances?
| 5,000,542 |
1 | 3 | 0 | 0 | 9 | 1 | 0 | 0 |
I am using M2Crypto's AES for encrypting message, but confused about how to generate a strong random session key and of what length. Does M2Crypto provide any function for generation random key.
| 0 |
python,m2crypto
|
2011-02-15T07:35:00.000
| 0 | 5,000,946 |
If you are encrypting to send to another party then you want to do something like Diffie Hellman or ECDH key exchange to establish a shared secret. If you just want to encrypt for storage, then you need a secure random number generator. I do not believe M2Crypto provides this?
It looks like M2Crypto does support Diffie Hellman.
| 0 | 21,236 | false | 0 | 1 |
How to generate strong one time session key for AES in python
| 5,002,066 |
1 | 1 | 0 | 1 | 0 | 0 | 0.197375 | 0 |
I need to compare values that i have by executing wmi commands(using python) and values from inside a db.. is it best to compare them without storing in separate files or is storing and then comparing is the only possible way?
can someone pls direct me in the right way.. also, where should i look for, for getting more knowledge regarding this?
| 0 |
python,comparison
|
2011-02-15T10:17:00.000
| 0 | 5,002,359 |
If in doubt, go for the simplest solution. In this case, compare them in memory.
If you want to be ultra-reliable (i.e. survive after crashes of your application / power outage) or cache values for long times (i.e. it's a requirement to continue working even when the database is down), you may consider files. Be warned though - anything but an extremely careful implementation (you should have lots of try..except..finallys and at least one call to flock and fsync, storing in files tends to be less reliable. So unless you're interested in consistency research and willing to put up a few weeks, go for a simple Python comparison.
| 0 | 43 | false | 0 | 1 |
i need some directions in comparing values from different sources using python
| 5,002,512 |
2 | 3 | 0 | 0 | 2 | 0 | 1.2 | 0 |
I have a web app that needs both functionality and performance tested, and part of the test suite that we plan on using is already written in Python. When I first wrote this, I used mechanize as my means of web-scraping, but it seems to be too bulky for what I'm trying to do (either that or I'm missing something).
The basic layout of what I'm trying to do is as follows. All are objects.
User has Comm (used to be the interface between my stuff and mechanize)
Comm has Browser (holds my CookieJar, urllib2, and BeautifulSoup objects, used to be mechanize)
Browser has Form(s) (used to be mechanize-handled)
Now, as far as threading goes, I have that down. Adjustment between dealing with the GIL and having separate instances of Python running will be made as needed, but suggestions will be taken.
So what I need to do is thread users hitting the application and doing various things (logging in, filling out forms, submitting forms for processing, etc.) while not making the testing box scream too loudly. My current problem with mechanize seems to be RAM.
Part of what's causing the RAM issue is the need for separate browser instances for each user to keep from overwriting the JSESSIONID cookie every time I do something with a different user.
Much of this might seem trivial, but I'm trying to run thousands of threads here, so little tweaks can mean a lot. Any input is appreciated.
| 0 |
python,automated-tests,web-scraping,urllib2,mechanize-python
|
2011-02-15T11:22:00.000
| 0 | 5,002,986 |
I actually went without using mechanize and used the Threading module. This allowed for fairly quick transactions, and I also made sure not to have too much inside of each thread. Login information, and getting the webapp in the state necessary before I threaded helped the threads to run shorter and therefore more quickly.
| 0 | 929 | true | 1 | 1 |
Python web-scraping threaded performance
| 5,462,848 |
2 | 3 | 0 | 0 | 2 | 0 | 0 | 0 |
I have a web app that needs both functionality and performance tested, and part of the test suite that we plan on using is already written in Python. When I first wrote this, I used mechanize as my means of web-scraping, but it seems to be too bulky for what I'm trying to do (either that or I'm missing something).
The basic layout of what I'm trying to do is as follows. All are objects.
User has Comm (used to be the interface between my stuff and mechanize)
Comm has Browser (holds my CookieJar, urllib2, and BeautifulSoup objects, used to be mechanize)
Browser has Form(s) (used to be mechanize-handled)
Now, as far as threading goes, I have that down. Adjustment between dealing with the GIL and having separate instances of Python running will be made as needed, but suggestions will be taken.
So what I need to do is thread users hitting the application and doing various things (logging in, filling out forms, submitting forms for processing, etc.) while not making the testing box scream too loudly. My current problem with mechanize seems to be RAM.
Part of what's causing the RAM issue is the need for separate browser instances for each user to keep from overwriting the JSESSIONID cookie every time I do something with a different user.
Much of this might seem trivial, but I'm trying to run thousands of threads here, so little tweaks can mean a lot. Any input is appreciated.
| 0 |
python,automated-tests,web-scraping,urllib2,mechanize-python
|
2011-02-15T11:22:00.000
| 0 | 5,002,986 |
Have you considered Twisted, the asynchronous library, for at least doing interaction with users?
| 0 | 929 | false | 1 | 1 |
Python web-scraping threaded performance
| 5,236,735 |
2 | 4 | 0 | 0 | 3 | 1 | 0 | 1 |
I'm trying to determine which files in the Python library are strictly necessary for my script to run. Right now I'm trying to determine where _io.py is located. In io.py (no underscore), the _io.py module (with underscore) is imported on line 60.
| 0 |
python,embed,portability
|
2011-02-15T11:50:00.000
| 0 | 5,003,276 |
Try the DLLs folder under your base python install directory if you are on windows. It contains .pyd modules Ignacio mentions. I had a similar problem with a portable install. Including the DLLs folder contents to my install fixed it. I am using python 2.5.
| 0 | 2,239 | false | 0 | 1 |
Python: import _io
| 5,003,499 |
2 | 4 | 0 | 1 | 3 | 1 | 0.049958 | 1 |
I'm trying to determine which files in the Python library are strictly necessary for my script to run. Right now I'm trying to determine where _io.py is located. In io.py (no underscore), the _io.py module (with underscore) is imported on line 60.
| 0 |
python,embed,portability
|
2011-02-15T11:50:00.000
| 0 | 5,003,276 |
Not all Python modules are written in Python. Try looking for _io.so or _io.pyd.
| 0 | 2,239 | false | 0 | 1 |
Python: import _io
| 5,003,294 |
1 | 2 | 0 | 0 | 0 | 1 | 0 | 0 |
I am searching to download the python dlls email, getpass, imaplib, os and use that in vb.net to get the gmail email with attachments
| 0 |
python
|
2011-02-15T15:27:00.000
| 0 | 5,005,613 |
Python doesn't have DLLs which you can simply use with VB.net. Your fundamental understanding of the modules libraries is flawed.
| 0 | 183 | false | 0 | 1 |
From where can we download the python dlls email, getpass, imaplib, os
| 5,005,639 |
1 | 2 | 0 | 0 | 0 | 0 | 0 | 0 |
I have a MATLAB function that needs to communicate (not rapidly, and not often) with python code. I have MATLAB write numbers to a file. Python reads the file, does some calculations, and writes some results to another file. MATLAB then reads that file and continues on its way.
The problem I am having is when I want to execute the python script from MATLAB. I have found in the past that simply performing a system call within MATLAB has been sufficient:
system('python myscript.py')
However, it seems to not like the numpy function 'loadtxt' when it reaches that point in the python script:
NameError: name 'loadtxt' is not defined
I am defining it (from numpy import *). If I just execute the script from terminal, it reads in the file using loadtxt just fine. It is only when I execute the script using the system call do I get that error. The python .py file is in the same directory as the MATLAB .m file that is making the system call. I have executed other scripts without loadtxt just fine using this same method.
Any suggestions?
| 0 |
python,matlab,numpy
|
2011-02-15T17:01:00.000
| 1 | 5,006,837 |
The shell on your system and the shell opened by Matlab when you execute the system command are not necessarily the same.
Importantly, there could be different environment variables. Try e.g. executing system('echo $PATH') to check whether you have access to all your libraries.
| 0 | 2,383 | false | 0 | 1 |
Problem with using system call to execute python script from MATLAB
| 5,007,373 |
4 | 5 | 0 | 1 | 5 | 0 | 1.2 | 0 |
I want to use a Python framework that handles sessions (user auth), templating along with MySQL database access (although I can use MySQLdb quite nicely)
Tornado looks promising but, I just can't see how to use it. The sample given has a port listen feature. Does it replace Apache? Exactly how do I configure my server (Centos 5.4) and LAMP setup for this, or is there a better option?
| 0 |
python,tornado
|
2011-02-16T00:25:00.000
| 1 | 5,011,135 |
Use Django.
I'm a hardcore Tornado fan but if you need to ask, Django is the best tool for you. Tornado is great but Django is much easier to build when you need a MySQL database thanks to its awesome ORM.
| 0 | 4,348 | true | 0 | 1 |
python tornado setup
| 12,342,342 |
4 | 5 | 0 | 0 | 5 | 0 | 0 | 0 |
I want to use a Python framework that handles sessions (user auth), templating along with MySQL database access (although I can use MySQLdb quite nicely)
Tornado looks promising but, I just can't see how to use it. The sample given has a port listen feature. Does it replace Apache? Exactly how do I configure my server (Centos 5.4) and LAMP setup for this, or is there a better option?
| 0 |
python,tornado
|
2011-02-16T00:25:00.000
| 1 | 5,011,135 |
If you are using tornado follow nginx.
| 0 | 4,348 | false | 0 | 1 |
python tornado setup
| 31,242,703 |
4 | 5 | 0 | 1 | 5 | 0 | 0.039979 | 0 |
I want to use a Python framework that handles sessions (user auth), templating along with MySQL database access (although I can use MySQLdb quite nicely)
Tornado looks promising but, I just can't see how to use it. The sample given has a port listen feature. Does it replace Apache? Exactly how do I configure my server (Centos 5.4) and LAMP setup for this, or is there a better option?
| 0 |
python,tornado
|
2011-02-16T00:25:00.000
| 1 | 5,011,135 |
if you using tornado for websockets you can use ha-proxy for proxying socket request to tornado (ngnix not support this)
| 0 | 4,348 | false | 0 | 1 |
python tornado setup
| 8,414,532 |
4 | 5 | 0 | 0 | 5 | 0 | 0 | 0 |
I want to use a Python framework that handles sessions (user auth), templating along with MySQL database access (although I can use MySQLdb quite nicely)
Tornado looks promising but, I just can't see how to use it. The sample given has a port listen feature. Does it replace Apache? Exactly how do I configure my server (Centos 5.4) and LAMP setup for this, or is there a better option?
| 0 |
python,tornado
|
2011-02-16T00:25:00.000
| 1 | 5,011,135 |
If you setup tornado via LAMP (apache with mod_wsgi for example) you will lose every single async option in tornado, significant amount of memory and speed.
It's highly recomended to use nginx for serving static files and proxying dynamic requests to the tornado application instance.
| 0 | 4,348 | false | 0 | 1 |
python tornado setup
| 7,278,376 |
2 | 4 | 0 | 1 | 7 | 1 | 0.049958 | 0 |
I have a command line program written in Python, and when I pipe it through another program on the command line, sys.stdout.encoding is None. This makes sense, I suppose -- the output could be another program, or a file you're redirecting it into, or whatever, and it doesn't know what encoding is desired. But neither do I! This program will be used by many different people (humor me) in different ways. Should I play it safe and output only ascii (replacing non-ascii chars with question marks)? Or should I output UTF-8, since it's so widespread these days?
| 0 |
python,linux,shell,command-line,unicode
|
2011-02-16T07:22:00.000
| 1 | 5,013,599 |
if your application doesn't really deal with a whole lot of internationalisation, ascii should suffice. but if not, i'd say utf-8 or better still utf-16 should be the order of the day.
| 0 | 430 | false | 0 | 1 |
If a command line program is unsure of stdout's encoding, what encoding should it output?
| 5,013,663 |
2 | 4 | 0 | 0 | 7 | 1 | 0 | 0 |
I have a command line program written in Python, and when I pipe it through another program on the command line, sys.stdout.encoding is None. This makes sense, I suppose -- the output could be another program, or a file you're redirecting it into, or whatever, and it doesn't know what encoding is desired. But neither do I! This program will be used by many different people (humor me) in different ways. Should I play it safe and output only ascii (replacing non-ascii chars with question marks)? Or should I output UTF-8, since it's so widespread these days?
| 0 |
python,linux,shell,command-line,unicode
|
2011-02-16T07:22:00.000
| 1 | 5,013,599 |
You should output UTF-8 because thats what everyone should be using. It's a bug not to be. ;)
| 0 | 430 | false | 0 | 1 |
If a command line program is unsure of stdout's encoding, what encoding should it output?
| 5,013,662 |
1 | 2 | 0 | 4 | 5 | 0 | 0.379949 | 0 |
This has been bugging me for awhile now.
In a deployed PHP web application one can upload a changed php script and have the updated file picked up by the web server without having to restart.
The problem? Ruby, Groovy, & Python, etc. are all "better" than PHP in terms of language expressiveness, concision, power, ...your-reason-here.
Currently, I am really enjoying Groovy (via Grails), but the reality is that the JVM does not do well (at all) with production dynamic reloading of application code. Basically, Permgen out of memory errors are a virtual guarantee, and that means application crash at anytime -- not good.
Ruby frameworks seem to have this solved somewhat from what I have read: Passenger has an option to dynamically reload changed files in polled directories on the next request (thus preventing connected users from being disconnected, session lost, etc.).
Standalone Python I am not sure about at all; it may, like PHP allow dynamic reloading of python scripts without web server restart.
As far as our web work is concerned, invariably clients wind up wanting to make changes to a deployed application regardless of how detailed and well planned the spec was. Telling the client, "sure, we'll implement that [simple] change at 4AM tomorrow [so as to not wreak havoc with connected users]", won't go over too well.
As of 2011 where are we at in terms of dynamic reloading and scripting languages? Are we forever doomed, relegated to the convenience of PHP, or the joys of non-PHP and being forced to restart a deployed application?
BTW, I am not at all a fan of JSPs, GSPs, and Ruby, Python templating equivalents, despite their reloadability. This is a cake & eat it too thread, where we can make a change to any aspect of the application and not have to restart.
| 0 |
php,python,ruby,groovy,reloading
|
2011-02-16T07:56:00.000
| 0 | 5,013,863 |
I think you're making a bigger deal out of this than it really is.
Any application for which it is that important that it never be down for 1/2 a minute (which is all it takes to reboot a server to pick up a file change) really needs to have multiple application server instances in order to handle potential failures of individual instances. Once you have multiple application servers to handle failures, you can also safely restart individual instances for maintenance without causing a problem.
| 0 | 368 | false | 1 | 1 |
2011 Web Scripting Languages and Dynamic Reloading
| 5,014,150 |
1 | 1 | 0 | 4 | 4 | 0 | 0.664037 | 0 |
Hi
I am trying to Understand if tornado/eventlet based http sever are better than threaded sever. While goggling the subject I am seeing that these are single thread event base server which run a single handler function after select/poll/epoll on socket.
My first question is that is this tornado/eventlet similar to nio library in java and is a java nio server non-blocking and fast.
My second question is that since this event based Server are single thread If one connection blocks on file io or solw client will it hang the entire server
My third question is that what is the trade off , if non blocking server is fast why isn't it is more common than apache
These questions are related and I would apprecite as I am not understanding these issues correctly
Thanks
| 0 |
java,python,http,asynchronous,nonblocking
|
2011-02-17T06:31:00.000
| 1 | 5,025,770 |
Nonblocking servers are the best choice provided all your libraries provides nonblocking apis. As mentioned in your second question if a library blocks (eg database lib making a blocking call), the entire process/thread blocks and the system hangs. Not all of the libraries available are asynchronous which makes it difficult to use tornado/eventlet for all usecases. Also in a multi-core box multiple instances of nonblocking servers needs to be started to use the box capacity completly.
Tornado/Event servers are similar to java nio based servers. There is one conceptual difference between a Tornado and Eventlet. Tornado follows a reactor pattern where the single process waits for IO(socket) events and dispatches them to appropriate handlers. If handlers are nonblocking, best performance can be expected. Typically code written for these frameworks consists of a series of callbacks making it a bit less readable than a synchronous server .Java NIO servers comes under this category.
Eventlet performs the same task but with a cleaner interface. Code can be written as in the case of synchronous server without using callbacks. When an IO is encountered, eventlet schedules another userspace process(not right terminology).
Apache webapps are more popular that these because of few reasons
It is relatively easy to write synchronous code
Not all required libraries are asynchronous.
But for writing a chat application which handles lots of connections a multi-threaded server will not scale. You have to use async frameworks like twisted/event/Java NIO.
| 0 | 2,292 | false | 1 | 1 |
Non-blocking http server , java nio , python tornado eventlet
| 5,049,188 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.