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
6
0
1
3
1
0.033321
0
I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can import mylib from within my application. I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repository and work within that branch. To test my application with the changes I am making to the library I edit the path in "mylib.pth" to point to the new development branch. This gets a little tedious if I have a few parallel branches of my library going on at one. I have to keep editing the "mylib.pth" file before testing to ensure I am testing against the correct version of my library. Is there a way to use the current path (i.e. the development branch of the library that I am current in) to set the library path when I invoke my application instead of using the "mylib.pth" in the global "site-packages" directory?
0
python
2009-12-11T18:25:00.000
0
1,889,967
Sure, you can alter sys.path to add the current directory (or a subdirectory of it) to the search path. site.addsitedir is a good way to do it. Since you'd be doing this from Python you can have any sort of logic you like for deciding which directory to add; you could base it on os.path.normpath​ing the current directory if it looks like a branch, or looking for the newest branch on-disc, or something else. You could put this code in the sitecustomize.py module or other startup-triggered location.
0
683
false
0
1
Setting Python path while developing library module
1,890,161
2
6
0
2
3
1
0.066568
0
I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can import mylib from within my application. I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repository and work within that branch. To test my application with the changes I am making to the library I edit the path in "mylib.pth" to point to the new development branch. This gets a little tedious if I have a few parallel branches of my library going on at one. I have to keep editing the "mylib.pth" file before testing to ensure I am testing against the correct version of my library. Is there a way to use the current path (i.e. the development branch of the library that I am current in) to set the library path when I invoke my application instead of using the "mylib.pth" in the global "site-packages" directory?
0
python
2009-12-11T18:25:00.000
0
1,889,967
If you use setuptools, then you can say setup.py develop in your working tree, and it will do the .pth file manipulation for you.
0
683
false
0
1
Setting Python path while developing library module
1,890,000
7
9
0
17
6
0
1
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
Just use Python. You'll have access to the same low-level socket APIs as in C, without having to learn about indirection and memory management at the same time. Later, if you find that Python is too slow for your purposes, you can rewrite some parts in C. But don't do it to begin with.
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
1,891,560
7
9
0
5
6
0
0.110656
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
Depending on what level(s) of the networking stack you want to work, C may be indispensable, useful, or hardly relevant. But if trying to tackle C first is wearing down your motivation, by all means go back to Python and get some success and therefore incentive -- you can come back to C later. Learning an easier language first, a harder one later, is a perfectly natural progression! MIT, for example, uses Python for some "programming 101" courses -- and yet, most definitely, that doesn't turn students off harder languages such as C (or even C++, which is harder yet!) in later courses.
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
1,891,571
7
9
0
5
6
0
0.110656
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
Twenty years ago, even ten, you couldn't live without it. Now many do. It's possible (probable, actually) that more than half the programmers in the world don't know C. It's completely unnecessary for Web work and for most app work. I'm being gracious with this--if you really were to include web, hobby, overseas consultants and the like, the percent who have used C is probably pretty low at this point. Embedded often uses C, but I've worked on 2 embedded platforms (a waveform analyzer and cable box) where I've done nothing but Java work. Honestly a basic understanding of C is nice for writing drivers and understanding pointers, but these days you can easily get through an entire career without ever needing C. I personally would completely skip C++, although it's used quite a bit, I don't see any big advantages to learning it now.
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
1,891,586
7
9
0
1
6
0
0.022219
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
As a python programmer, I would give you the opposite advice. Learn python first. At least until you learn the limitations and possibilities it has compared to what you can do in C. Then use C for those far out problems you can't fix in Python. :)
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
1,891,569
7
9
0
1
6
0
0.022219
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
I would recommend starting with Python, unless you absolutely need the speed. It's often said that programming languages are just tools in your toolbox, and certain ones are going to be able to accomplish a given task better than others. If you don't need the speed, Python is going to accomplish the task you're looking to accomplish with less code and will be easier to learn. I am entirely self-taught and went from Apple II BASIC to assembly language to scripting languages (Perl, PHP, Ruby) and now am using mostly C. C is a relatively small language, but I believe that had I started out with C, I probably would've lost my motivation. Start out with Python - you'll learn the gist of programming, then if you have the need or the want to learn C later, it will be easier to pick up.
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
1,891,955
7
9
0
2
6
0
0.044415
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
I would recommend using Python. Because it is a higher level language than C, you can concentrate more on the "what" rather than the "how". This means that you can avoid the level of detail required by C in order to achieve what you need to get done right now. This isn't to say that a low level of detail is never required. It certainly is, but at this time I'd recommend you ignore it and pick it up in the future, should you need to.
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
1,891,967
7
9
0
0
6
0
0
0
I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody(with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right. So I've been with a k&r for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C. Question: Should I continue battling with C like i'm now and write some working code in it or switch to python where i'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?
0
python,c,networking
2009-12-11T23:32:00.000
0
1,891,551
learn lisp, its performance is almost that of C and its easy to learn and you can do more in lisp than you can in python and its not hard to learn. You can also do natural language programming to solve problems. go lisp.
0
8,819
false
0
1
Network programming: Python vs. C for a complete beginner
14,009,100
1
3
0
1
2
0
0.066568
0
We have a collection of Unix scripts (and/or Python modules) that each perform a long running task. I would like to provide a web interface for them that does the following: Asks for relevant data to pass into scripts. Allows for starting/stopping/killing them. Allows for monitoring the progress and/or other information provided by the scripts. Possibly some kind of logging (although the scripts already do logging). I do know how to write a server that does this (e.g. by using Python's built-in HTTP server/JSON), but doing this properly is non-trivial and I do not want to reinvent the wheel. Are there any existing solutions that allow for maintaining asynchronous server-side tasks?
0
python,http,unix,asynchronous
2009-12-13T21:07:00.000
1
1,897,748
Django is great for writing web applications, and the subprocess module (subprocess.Popen en .communicate()) is great for executing shell scripts. You can give it a stdin,stdout and stderr stream for communication if you want.
0
257
false
0
1
Executing server-side Unix scripts asynchronously
1,897,759
1
4
0
0
6
1
0
0
We have a common python installation for all of our systems in order to ensure every system has the same python installation and to ease configuration issues. This installation is located on a shared drive. We also have multiple platforms that share this installation. We get around conflicting platform-specific files by setting the --exec-prefix configure option when compiling python. My issue is that I now want to install an egg using easy_install (or otherwise) that is platform-dependent. easy_install puts the egg in the site-packages directory of the platform-independent part of the install. The name of the egg has the platform in it so there should be no conflict. But python will only load the first one it finds. (So, on Solaris it might try to load the Linux egg). Modifying the easy-install.pth file can change which one it finds, but that's pretty useless. I can move the .egg files into a platform-depended packages directory and then use pkg_resources.require() to load them (or manually adjust the path). But it seems as though I shouldn't have to since the platform is in the name of the egg. Is there any more generic way I can ensure that python will load the egg for the correct platform?
0
python,easy-install,pkg-resources
2009-12-14T21:33:00.000
1
1,903,653
Use "easy_install -m" to install all the platform-specific packages, so that there is no default version on sys.path. That way, version resolution takes place at runtime, and platform information will be taken into consideration.
0
1,197
false
0
1
How can I deal with python eggs for multiple platforms in one location?
2,164,148
1
1
0
0
1
0
0
0
I have a python script on a linux server that I can SSH into and I want to run the script on the linux server( and pass it parameters entered by the user) and get the output on an ASP.net webpage running on IIS. How would I be able to do that? Would it be easier if I was running a wamp server? Edit: The servers are in the same internal intranet.
0
asp.net,python,remote-execution
2009-12-14T23:40:00.000
1
1,904,320
Probably the best approach is the least coupled one. If you can determine a protocol that you're comfortable with the two (asp/python) talking in, it will go a long way to reducing headaches. Let's say you pick XML. Setup the python script to run as a WSGI application with either cherrypy or apache (or whatever). The script formats it's response in XML and passes that to WSGI which returns the XML over HTTP. On the ASP.NET side of things, whenever you want to "run the script" you simply query the URL with the WebRequest class, then parse the results with LINQ-to-XML (which on a side note is a really cool technology). Here's where this becomes relevant: Later on if either the ASP.NET implementation or the python implementation changes you don't have to re-code/refactor the other. Later if you realize that the ASP.NET app and some desktop app need to be able to do that, you've standardized on a protocol and implementing it should be easy and well supported.
0
1,105
false
0
1
Run a remote python script from ASP.Net
1,904,344
2
3
0
0
4
0
0
0
This might sound really crazy, but still... For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a header and footer (PHP) into the Trac template (preferrably without invoking a - or rather two for header and footer - PHP process from the command line)?
0
php,python,integration,trac
2009-12-15T14:21:00.000
0
1,907,782
Your Python code will have access to your users' cookies. A template would be best, but if you don't have one available (or the header/footer are trivially small, or whatever), you can simply port the PHP header and footer code to Python, using the cookies that are already there to query the database or whatever you need to do. If you want to retain your links for logging in, registering, and whatever else might be in the PHP version, simply link to the PHP side, then redirect back to Trac once PHP's done its job.
0
2,293
false
1
1
Integrate Python app into PHP site
1,909,272
2
3
0
1
4
0
0.066568
0
This might sound really crazy, but still... For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a header and footer (PHP) into the Trac template (preferrably without invoking a - or rather two for header and footer - PHP process from the command line)?
0
php,python,integration,trac
2009-12-15T14:21:00.000
0
1,907,782
The best option probably is to (re)write the header and footer using python. If the header and footer are relatively static you can also generate them once using php (or once every x minutes) and include them from the filesystem. (You probably already thought about this and dismissed the idea because your sites are too dynamic to use this option?) While I would not really recommend it you could also use some form of AJAX to load parts of the page, and nothing prevents you from loading this content from a php based system. That could keep all parts dynamic. Your pages will probably look ugly while loading, and you now generate more hits on the server than needed, but if it is nog a big site this might be a big. Warning: If you have user logins on both systems you will probably run into problems with people only being logged in to half of your site.
0
2,293
false
1
1
Integrate Python app into PHP site
1,907,850
2
5
0
4
10
1
0.158649
0
I started with c++ but as we all know, c++ is a monster. I still have to take it and I do like C++ (it takes programming a step further) However, currently I have been working with python for a while. I see how you guys can turn some long algorithm into simple one. I know programming is a progress, and can take up to years of experience. I also know myself - I am not a natural programmer, and software engineering is not my first choice anyway. However, I would like to do heavy programming on my own, and create projects. How can I become a better python programmer?
0
python
2009-12-15T15:37:00.000
0
1,908,250
One suggestion is to find an open-source project in Python, and start contributing. You may ask "how can I contribute, if I'm a beginner?". One answer is "write tests". Almost any project will welcome you as a tester. Another answer is "documentation", though that is less likely to give immediate benefits.
0
8,219
false
0
1
How to become a good Python coder?
1,908,528
2
5
0
3
10
1
0.119427
0
I started with c++ but as we all know, c++ is a monster. I still have to take it and I do like C++ (it takes programming a step further) However, currently I have been working with python for a while. I see how you guys can turn some long algorithm into simple one. I know programming is a progress, and can take up to years of experience. I also know myself - I am not a natural programmer, and software engineering is not my first choice anyway. However, I would like to do heavy programming on my own, and create projects. How can I become a better python programmer?
0
python
2009-12-15T15:37:00.000
0
1,908,250
The already-posted answers are great. In addition, whenever you're coding something in Python and you start doing something that feels clumsy, take a step back and think. If you can't think of a more elegant way to do it, post it as a question on Stack Overflow. I can't count the number of times that I've seen someone reduce ten lines of Python into one (which is still perfectly easy to read and understand).
0
8,219
false
0
1
How to become a good Python coder?
1,908,456
2
2
0
1
10
0
0.099668
0
my question simply relates to the difference in performance between a socket in C and in Python. Since my Python build is CPython, I assume it's similar, but I'm curious if someone actually has "real" benchmarks, or at least an opinion that's evidence based. My logics is as such: C socket much faster? then write a C extension. not/barely a difference? keep writing in Python and figure out how to obtain packet level control (scapy? dpkt?) I'm sure someone will want to know for either context or curiosity. I plan to build a sort of proxy for myself (not for internet browsing, anonymity, etc) and will bind the application I want to use with it to a specific port. Then, all packets on said port will be queued, address header modified, and then sent, etc, etc. Thanks in advance.
0
python,c,sockets,scapy
2009-12-15T18:39:00.000
0
1,909,471
i would think C would be faster, but python would be a lot easier to manage and use. the difference would be so small, you wouldn't need it unless you were trying to send masses amount of data (something stupid like 1 million gb/second lol) joe
0
4,477
false
0
1
C/Python Socket Performance?
1,909,504
2
2
0
13
10
0
1.2
0
my question simply relates to the difference in performance between a socket in C and in Python. Since my Python build is CPython, I assume it's similar, but I'm curious if someone actually has "real" benchmarks, or at least an opinion that's evidence based. My logics is as such: C socket much faster? then write a C extension. not/barely a difference? keep writing in Python and figure out how to obtain packet level control (scapy? dpkt?) I'm sure someone will want to know for either context or curiosity. I plan to build a sort of proxy for myself (not for internet browsing, anonymity, etc) and will bind the application I want to use with it to a specific port. Then, all packets on said port will be queued, address header modified, and then sent, etc, etc. Thanks in advance.
0
python,c,sockets,scapy
2009-12-15T18:39:00.000
0
1,909,471
In general, sockets in Python perform just fine. For example, the reference implementation of the BitTorrent tracker server is written in Python. When doing networking operations, the speed of the network is usually the limiting factor. That is, any possible tiny difference in speed between C and Python's socket code is completely overshadowed by the fact that you're doing networking of some kind. However, your description of what you want to do indicates that you want to inspect and modify individual IP packets. This is beyond the capabilities of Python's standard networking libraries, and is in any case a very OS-dependent operation. Rather than asking "which is faster?" you will need to first ask "is this possible?"
0
4,477
true
0
1
C/Python Socket Performance?
1,909,511
1
2
0
134
105
1
1
0
What is Python used for and what is it designed for?
0
python
2009-12-15T18:46:00.000
0
1,909,512
Python is a dynamic, strongly typed, object oriented, multipurpose programming language, designed to be quick (to learn, to use, and to understand), and to enforce a clean and uniform syntax. Python is dynamically typed: it means that you don't declare a type (e.g. 'integer') for a variable name, and then assign something of that type (and only that type). Instead, you have variable names, and you bind them to entities whose type stays with the entity itself. a = 5 makes the variable name a to refer to the integer 5. Later, a = "hello" makes the variable name a to refer to a string containing "hello". Static typed languages would have you declare int a and then a = 5, but assigning a = "hello" would have been a compile time error. On one hand, this makes everything more unpredictable (you don't know what a refers to). On the other hand, it makes very easy to achieve some results a static typed languages makes very difficult. Python is strongly typed. It means that if a = "5" (the string whose value is '5') will remain a string, and never coerced to a number if the context requires so. Every type conversion in python must be done explicitly. This is different from, for example, Perl or Javascript, where you have weak typing, and can write things like "hello" + 5 to get "hello5". Python is object oriented, with class-based inheritance. Everything is an object (including classes, functions, modules, etc), in the sense that they can be passed around as arguments, have methods and attributes, and so on. Python is multipurpose: it is not specialised to a specific target of users (like R for statistics, or PHP for web programming). It is extended through modules and libraries, that hook very easily into the C programming language. Python enforces correct indentation of the code by making the indentation part of the syntax. There are no control braces in Python. Blocks of code are identified by the level of indentation. Although a big turn off for many programmers not used to this, it is precious as it gives a very uniform style and results in code that is visually pleasant to read. The code is compiled into byte code and then executed in a virtual machine. This means that precompiled code is portable between platforms. Python can be used for any programming task, from GUI programming to web programming with everything else in between. It's quite efficient, as much of its activity is done at the C level. Python is just a layer on top of C. There are libraries for everything you can think of: game programming and openGL, GUI interfaces, web frameworks, semantic web, scientific computing...
0
155,982
false
0
1
What is Python used for?
1,923,081
4
6
0
0
8
1
0
0
I am learning IronPython along wiht Python. I'm curious what kinds of tasks you tend to use IronPython to tackle more often than standard .NET languages. Thanks for any example.
0
python,ironpython
2009-12-16T07:36:00.000
0
1,912,971
We use it a lot for small administrative tools against SharePoint. In particular it is fantastic for exploring the API against real data (with all its real life quirks). Development iterations are faster and you can't always install Visual Studio on production servers.
0
797
false
0
1
IronPython: What kind of jobs you ever done with IronPython instead of standard .NET languages (e.g., C#)
10,440,546
4
6
0
0
8
1
0
0
I am learning IronPython along wiht Python. I'm curious what kinds of tasks you tend to use IronPython to tackle more often than standard .NET languages. Thanks for any example.
0
python,ironpython
2009-12-16T07:36:00.000
0
1,912,971
I use IronPython for a few different purposes: An alternative to Powershell when I need to script something and invoke a .NET library, or when the script is complicated enough to warrant a real programming language. Embedding in a .NET app for scriptable plugins. Prototyping and testing .NET libs in immediate mode. This is way easier than making a test project in C#
0
797
false
0
1
IronPython: What kind of jobs you ever done with IronPython instead of standard .NET languages (e.g., C#)
10,438,778
4
6
0
3
8
1
0.099668
0
I am learning IronPython along wiht Python. I'm curious what kinds of tasks you tend to use IronPython to tackle more often than standard .NET languages. Thanks for any example.
0
python,ironpython
2009-12-16T07:36:00.000
0
1,912,971
In the day job, it's my standard language for those little bits of build process that are too much for .bat files and not heavyweight enough to demand a separate executable; this includes anything that could use a little bit of XML processing or reflection -- generating Wix files with systematic handling of 32 and 64 bit installs, for example. It beats out PowerShell in this role because IronPython is an XCOPY install onto build machines. It's also very useful for prototyping fragments of code against unfamiliar or complex APIs (WMI and Active Directory being the usual ones for me), or diagnosing problems in code using those APIs (like sniffing out the oddities that happen when you're on the domain controller, rather than elsewhere).
0
797
false
0
1
IronPython: What kind of jobs you ever done with IronPython instead of standard .NET languages (e.g., C#)
1,913,029
4
6
0
0
8
1
0
0
I am learning IronPython along wiht Python. I'm curious what kinds of tasks you tend to use IronPython to tackle more often than standard .NET languages. Thanks for any example.
0
python,ironpython
2009-12-16T07:36:00.000
0
1,912,971
Created a load tool for a MS Group Chat Server plugin. The GC API is in C#. I wrapped that into a dll and had FePy load it. The main application, configuration scripts etc are all in FePy.
0
797
false
0
1
IronPython: What kind of jobs you ever done with IronPython instead of standard .NET languages (e.g., C#)
1,913,220
1
5
0
5
0
0
0.197375
0
I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so \x90,\x21,\x51,\x91,\x40,\x33 format yy,mm,dd,hh,mm,ss I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contains 902151914033. I then need to reverse each 2 characters in the string. Can anyone give me some pointers? Many Thanks
0
python,bytearray,decode
2009-12-16T19:10:00.000
0
1,916,928
To convert to hex: hexdata = ''.join('%02x' % ord(byte) for byte in bindata) To reverse every other hex character (if I'm understanding correctly): hexdata = ''.join(('%02x' % ord(byte))[::-1] for byte in bindata)
0
10,490
false
0
1
convert byte array to string without interpreting the bytes?
1,917,086
1
2
0
11
13
1
1
0
I have two related Python 'import' questions. They are easily testable, but I want answers that are language-defined and not implementation-specific, and I'm also interested in style/convention, so I'm asking here instead. 1) If module A imports module B, and module B imports module C, can code in module A reference module C without an explicit import? If so, am I correct in assuming this is bad practice? 2) If I import module A.B.C, does that import modules A and A.B as well? If so, is it by convention better to explicitly import A; import A.B; import A.B.C?
0
python,coding-style,import,module,conventions
2009-12-16T21:41:00.000
0
1,917,958
Alan's given a great answer, but I wanted to add that for your question 1 it depends on what you mean by 'imports'. If you use the from C import x syntax, then x becomes available in the namespace of B. If in A you then do import B, you will have access to x from A as B.x. It's not so much bad practice as potentially confusing, and will make debugging etc harder as you won't necessarily know where the objects have come from.
0
3,559
false
0
1
Python import mechanics
1,918,234
1
3
0
1
2
0
0.066568
1
I have built an XML-RPC interface in Python and I need to enforce some stricter typing. For example, passing string '10' instead of int 10. I can clean this up with some type casting and a little exception handling, but I am wondering if there is any other way of forcing type integrity such as something XML-RPC specific, a decorator, or something else.
0
python,django
2009-12-18T00:12:00.000
0
1,925,487
It's always going to be converted to a string anyway, so why do you care what's being passed in? If you use "%s" % number or even just str(number), then it doesn't matter whether number is a string or an int.
0
220
false
0
1
XML-RPC method parameter data typing in Python
1,925,617
3
5
0
1
5
0
0.039979
0
We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an audio/mpeg stream in response. This is an expensive process. We're using Nginx as the front-end request handler. Nginx takes care of caching responses for common requests. We initially tried using Tornado on the back-end to handle requests from Nginx. As you would expect, the blocking MP3 operation kept Tornado from doing its thing (asynchronous I/O). So, we went multithreaded, which solved the blocking problem, and performed quite well. However, it introduced a subtle race condition (under real world load) that we haven't been able to diagnose or reproduce yet. The race condition corrupts our MP3 output. So we decided to set our application up as a simple WSGI handler behind Apache/mod_wsgi (still w/ Nginx up front). This eliminates the blocking issue and the race condition, but creates a cascading load (i.e. Apache creates too many processses) on the server under real world conditions. We're working on tuning Apache/mod_wsgi right now, but still at a trial-and-error phase. (Update: we've switched back to Tornado. See below.) Finally, the question: are we missing anything? Is there a better way to serve CPU-expensive resources over HTTP? Update: Thanks to Graham's informed article, I'm pretty sure this is an Apache tuning problem. In the mean-time, we've gone back to using Tornado and are trying to resolve the data-corruption issue. For those who were so quick to throw more iron at the problem, Tornado and a bit of multi-threading (despite the data integrity problem introduced by threading) handles the load acceptably on a small (single core) Amazon EC2 instance.
0
python,http,mod-wsgi,tornado
2009-12-18T17:39:00.000
1
1,929,681
You might consider a queuing system with AJAX notification methods. Whenever there is a request for your expensive resource, and that resource needs to be generated, add that request to the queue (if it's not already there). That queuing operation should return an ID of an object that you can query to get its status. Next you have to write a background service that spins up worker threads. These workers simply dequeue the request, generate the data, then saves the data's location in the request object. The webpage can make AJAX calls to your server to find out the progress of the generation and to give a link to the file once it's available. This is how LARGE media sites work - those that have to deal with video in particular. It might be overkill for your MP3 work however. Alternatively, look into running a couple machines to distribute the load. Your threads on Apache will still block, but atleast you won't consume resources on the web server.
0
495
false
1
1
Is there a better way to serve the results of an expensive, blocking python process over HTTP?
1,929,711
3
5
0
0
5
0
0
0
We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an audio/mpeg stream in response. This is an expensive process. We're using Nginx as the front-end request handler. Nginx takes care of caching responses for common requests. We initially tried using Tornado on the back-end to handle requests from Nginx. As you would expect, the blocking MP3 operation kept Tornado from doing its thing (asynchronous I/O). So, we went multithreaded, which solved the blocking problem, and performed quite well. However, it introduced a subtle race condition (under real world load) that we haven't been able to diagnose or reproduce yet. The race condition corrupts our MP3 output. So we decided to set our application up as a simple WSGI handler behind Apache/mod_wsgi (still w/ Nginx up front). This eliminates the blocking issue and the race condition, but creates a cascading load (i.e. Apache creates too many processses) on the server under real world conditions. We're working on tuning Apache/mod_wsgi right now, but still at a trial-and-error phase. (Update: we've switched back to Tornado. See below.) Finally, the question: are we missing anything? Is there a better way to serve CPU-expensive resources over HTTP? Update: Thanks to Graham's informed article, I'm pretty sure this is an Apache tuning problem. In the mean-time, we've gone back to using Tornado and are trying to resolve the data-corruption issue. For those who were so quick to throw more iron at the problem, Tornado and a bit of multi-threading (despite the data integrity problem introduced by threading) handles the load acceptably on a small (single core) Amazon EC2 instance.
0
python,http,mod-wsgi,tornado
2009-12-18T17:39:00.000
1
1,929,681
It looks like you are doing things right -- just lacking CPU power: can you determine what is the CPU loading in the process of generating these MP3? I think the next thing you have to do there is to add more hardware to render the MP3's on other machines. Or that or find a way to deliver pre-rendered MP3 (maybe you can cahce some of your media?) BTW, scaling for the web was the theme of a Keynote lecture by Jacob Kaplan-Moss on PyCon Brasil this year, and it is far from being a closed problem. The stack of technologies one needs to handle is quite impressible - (I could not find an online copy o f the presentation, though - -sorry for that)
0
495
false
1
1
Is there a better way to serve the results of an expensive, blocking python process over HTTP?
1,929,738
3
5
0
1
5
0
0.039979
0
We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an audio/mpeg stream in response. This is an expensive process. We're using Nginx as the front-end request handler. Nginx takes care of caching responses for common requests. We initially tried using Tornado on the back-end to handle requests from Nginx. As you would expect, the blocking MP3 operation kept Tornado from doing its thing (asynchronous I/O). So, we went multithreaded, which solved the blocking problem, and performed quite well. However, it introduced a subtle race condition (under real world load) that we haven't been able to diagnose or reproduce yet. The race condition corrupts our MP3 output. So we decided to set our application up as a simple WSGI handler behind Apache/mod_wsgi (still w/ Nginx up front). This eliminates the blocking issue and the race condition, but creates a cascading load (i.e. Apache creates too many processses) on the server under real world conditions. We're working on tuning Apache/mod_wsgi right now, but still at a trial-and-error phase. (Update: we've switched back to Tornado. See below.) Finally, the question: are we missing anything? Is there a better way to serve CPU-expensive resources over HTTP? Update: Thanks to Graham's informed article, I'm pretty sure this is an Apache tuning problem. In the mean-time, we've gone back to using Tornado and are trying to resolve the data-corruption issue. For those who were so quick to throw more iron at the problem, Tornado and a bit of multi-threading (despite the data integrity problem introduced by threading) handles the load acceptably on a small (single core) Amazon EC2 instance.
0
python,http,mod-wsgi,tornado
2009-12-18T17:39:00.000
1
1,929,681
Please define "cascading load", as it has no common meaning. Your most likely problem is going to be if you're running too many Apache processes. For a load like this, make sure you're using the prefork mpm, and make sure you're limiting yourself to an appropriate number of processes (no less than one per CPU, no more than two).
0
495
false
1
1
Is there a better way to serve the results of an expensive, blocking python process over HTTP?
1,937,378
1
1
0
4
1
1
0.664037
0
I have an object which defines a __deepcopy__ method. I would like a function that will deepcopy it not by the method given by it, but in the default way that objects of the class object are copied. How could I do that? I think I could try to code it but there are probably many "gotchas" I won't be thinking of. The reason I'm doing it is because I have an object class which implements a __deepcopy__ method, and that method checks for some condition, and in some cases it will deepcopy the object in a certain way, and in other cases it will deepcopy in the default object way.
0
python,deep-copy
2009-12-19T17:44:00.000
0
1,933,621
You basically need to override the existing __deepcopy__ method, which means temporarily setting the object's class to something different -- whether that's acceptable essentially depends on whether the "__deepcopy__ override" needs to affect only one, "top-level" object (in which case the kludge's probably OK), or if there are many objects of that class in the graph you're copying, in which case it's quite a mess. Which case obtains?
0
807
false
0
1
Deepcopy a simple Python object
1,933,642
2
3
0
1
4
1
0.066568
0
I know PHP a little. But Python is totally new for me. I only know it's something "similar", right? Or wrong? What are the differences I should know?
0
php,python
2009-12-20T15:07:00.000
0
1,936,085
One main difference is, that code formatting (indentation) influences your codes behaviour in Python. PHP is not interested in how you format your code. Furthermore PHP may be able to produce applications outside of webservers and CLIs but is definitely aimed at those two environments while Python is more "all purpose".
0
26,274
false
0
1
What are the major differences between Python and PHP?
1,936,148
2
3
0
16
4
1
1
0
I know PHP a little. But Python is totally new for me. I only know it's something "similar", right? Or wrong? What are the differences I should know?
0
php,python
2009-12-20T15:07:00.000
0
1,936,085
PHP is a language that's made for the web. You can make GTK and CLI applications with PHP, but it's mainly used for websites. Python is used for a lot of stuff like websites, webservers, game frameworks, desktop and CLI application, IDEs and a lot more. There's also a huge difference in the syntax. PHP has a syntax that's like C with curly braces for loops and whitespace is ignored. Python doesn't have curly braces, instead the level of indention of blocks of code are important. Both languages are easy to learn. It just depends on what you want to do.
0
26,274
false
0
1
What are the major differences between Python and PHP?
1,936,138
1
3
0
2
0
0
0.132549
1
I've import contacts from gmail by using gdata api, and is there any apis like that for hotmail/live/Aol ?
0
python,api
2009-12-21T08:50:00.000
0
1,938,945
There is Windows Live Contact API for Hotmail/Live mail. Yahoo Contact API for Yahoo also exists, but to this date, no AOL contact api. I would suggest you try openinviter (openinviter.com) to import contacts. Unfortunately, you will not have OAuth capabilities, but it is the best class out there and works with 90+ different email providers. Note: it is written in php, but creating a wrapper won't be too hard.
0
637
false
0
1
Is there any libraries could import contacts from hotmail/live/aol account?
1,939,043
1
1
0
1
2
0
1.2
0
Is there any way to use xbmc plugins in .net? im thinking about those plugins that provide access to media content like GameTrailers and stuff like that..
0
.net,python,xbmc
2009-12-21T13:40:00.000
0
1,940,150
I believe the plugin system is based on Python. You may be able to use IronPython to run some of the plugins in XBMC, although it may not be 100% compatible. You could also take the Python code and create a COM server object in which you could use .NET interop to interface with it.
0
318
true
0
1
Run XBMC plugins in a .net application
1,940,200
1
2
0
0
5
0
0
0
So I'm trying to do more web development in python, and I've picked cherrypy, hosted by lighttpd w/ fastcgi. But my question is a very basic one: why do I need to restart lighttpd (or apache) every time I change my application code, or the code for an underlying library? I realize this question extends from a basic mis(i.e. poor)understanding of the fastcgi model, so I'm open to any schooling here, but I'm used to just changing a PHP file and it showing up, versus having to bounce the web server. Any elucidation/useful mockery appreciated.
0
python,fastcgi,lighttpd,cherrypy
2009-12-22T16:09:00.000
0
1,947,344
From a system-software-writer's pointer of view: This all depends on how the meta-data about the server process is organized within your daemon (lighttpd or fcgi). Some programs are designed for one time only initialization -- MOSTLY this allows a much simpler and better performing internal programming model. Often it is very hard to program a server process reload config data in a easy way. You might have to introduce locks and external event objects (signals in UNIX). When you can synchronize the data structures by design -- i.e., only initializing once .... why complicate things by making the data model modifiable multiple times ?
0
2,035
false
1
1
fastcgi, cherrypy, and python
1,947,457
1
1
0
10
7
1
1.2
0
I am pretty sure that python scripts will work in all three, but I want to make sure. I have read here and there about editors that can write CPython, Jython, IronPython and I am hoping that I am looking to much into the distinction. My situation is I have 3 different api's that I want to test. Each api performs the same functionality code wise, but they are different in implementation. I am writing wrappers around each language's apis. Each wrapper should expose the exact same functionality and implementation to python using Boost::python, Jython, and IronPython. My question is, would a python script written using these exposed methods (that are common for each language) work in all three "flavors" of Python? Like I said I am pretty sure the answer is 'Of course,' but I need to make sure before I spend too much time working on this.
0
python,testing,ironpython,jython,boost-python
2009-12-23T16:56:00.000
0
1,953,989
The short answer is: Sometimes. Some projects built on top of IronPython may not work with CPython, and some CPython modules that are written in C (e.g. NumPy) will not work with IronPython. On a similar note, while Jython implements the language specification, it has several incompatibilities with CPython (for instance, it lacks a few parts of the CPython standard library, and it can import Java standard library packages and classes, like Swing) So, yes, as long as you avoid the incompatibilities.
0
1,142
true
0
1
Are CPython, IronPython, Jython scripts compatible with each other?
1,954,037
2
7
0
26
72
1
1
0
I am new to the Python programming language. I was wondering if it is possible to compile a program to written in Python. Is it possible to convert Python scripts to some lower level programming languages which then can be compiled to binary code? A developer who is considering to code in Python might want to keep the possibility open to be able to go for binary distribution later.
0
python,compilation
2009-12-24T06:36:00.000
0
1,957,054
Python, as a dynamic language, cannot be "compiled" into machine code statically, like C or COBOL can. You'll always need an interpreter to execute the code, which, by definition in the language, is a dynamic operation. You can "translate" source code in bytecode, which is just an intermediate process that the interpreter does to speed up the load of the code, It converts text files, with comments, blank spaces, words like 'if', 'def', 'in', etc in binary code, but the operations behind are exactly the same, in Python, not in machine code or any other language. This is what it's stored in .pyc files and it's also portable between architectures. Probably what you need it's not "compile" the code (which it's not possible) but to "embed" an interpreter (in the right architecture) with the code to allow running the code without an external installation of the interpreter. To do that, you can use all those tools like py2exe or cx_Freeze. Maybe I'm being a little pedantic on this :-P
0
159,831
false
0
1
Is it possible to compile a program written in Python?
1,957,814
2
7
0
-3
72
1
-0.085505
0
I am new to the Python programming language. I was wondering if it is possible to compile a program to written in Python. Is it possible to convert Python scripts to some lower level programming languages which then can be compiled to binary code? A developer who is considering to code in Python might want to keep the possibility open to be able to go for binary distribution later.
0
python,compilation
2009-12-24T06:36:00.000
0
1,957,054
python compile on the fly when you run it. Run a .py file by(linux): python abc.py
0
159,831
false
0
1
Is it possible to compile a program written in Python?
1,957,072
2
2
0
0
2
0
0
0
If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to /tmp) MySQL database? My application is in Python, and I'm using unittest on Ubuntu 9.10.
1
python,mysql,unit-testing,ubuntu
2009-12-25T00:25:00.000
0
1,960,155
You can try the Blackhole and Memory table types in MySQL.
0
287
false
0
1
Start a "throwaway" MySQL session for testing code?
1,960,164
2
2
0
1
2
0
1.2
0
If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to /tmp) MySQL database? My application is in Python, and I'm using unittest on Ubuntu 9.10.
1
python,mysql,unit-testing,ubuntu
2009-12-25T00:25:00.000
0
1,960,155
--datadir for just the data or --basedir
0
287
true
0
1
Start a "throwaway" MySQL session for testing code?
1,960,160
2
5
1
3
1
0
0.119427
0
I'm trying to extend Python interpreter by a few C functions I wrote. From reading docs, to expose those function the user has to import the module encompassing the functions. Is it possible to load pre-load or pre-import via C API the module so that the user doesn't have to type import <mymodule>? Or even better, from <mymodule> import <function>? Edit: I can do PyRun_SimpleString("from mymodule import myfunction") just after Py_Initialize(); - I was just wondering if there is another way of doing this..? Edit 2: In other words, I have an application written in C which embeds a Python interpreter. That application provides some functionality which I want to expose to the users so they can write simple Python scripts for the app. All I want is to remove the need of writing from mymodule import myfunction1, myfunction2 because, since it is very specialized app and the script wont work without the app anyway, it doesn't make sense to require to import ... all the time.
0
python,c,import,python-c-api,python-embedding
2009-12-26T14:05:00.000
0
1,963,453
Even if you implement a module in Python, the user would have to import it. This is the way Python works, and it's actually a good thing - it's one of the great pluses of Python - the namespace/module system is robust, easy to use and simple to understand. For academic exercises only, you could of course add your new functionality to Python itself, by creating a custom interpreter. You could even create new keywords this way. But for any practical purpose, this isn't recommended.
0
697
false
0
1
Extending Python: pre-load my C module
1,963,510
2
5
1
0
1
0
0
0
I'm trying to extend Python interpreter by a few C functions I wrote. From reading docs, to expose those function the user has to import the module encompassing the functions. Is it possible to load pre-load or pre-import via C API the module so that the user doesn't have to type import <mymodule>? Or even better, from <mymodule> import <function>? Edit: I can do PyRun_SimpleString("from mymodule import myfunction") just after Py_Initialize(); - I was just wondering if there is another way of doing this..? Edit 2: In other words, I have an application written in C which embeds a Python interpreter. That application provides some functionality which I want to expose to the users so they can write simple Python scripts for the app. All I want is to remove the need of writing from mymodule import myfunction1, myfunction2 because, since it is very specialized app and the script wont work without the app anyway, it doesn't make sense to require to import ... all the time.
0
python,c,import,python-c-api,python-embedding
2009-12-26T14:05:00.000
0
1,963,453
Nope. You could add it to the Python interpreter itself, but that would mean creating a custom Python version, which, I guess, is not what you want. That import <mymodule> is not just for loading the module, it's also for making this module visible in the (main|current) namespace. Being able to do that, w/o hacking the actual Python interpreter, would run against "Explicit is better than implicit" very strongly.
0
697
false
0
1
Extending Python: pre-load my C module
1,963,505
1
1
0
6
4
0
1.2
0
We're aiming to implement a scripting mechanism, using DLR's Microsoft.Scripting and hosting assembly. Now, someone knows about any performance difference between IronRuby 1.0 and IronPython 2.6? To my understanding they have different compilers, but IronPython seems more mature and tested, but if anyone has documentation or knowledge on this issue, that would be appreciated.
0
.net,performance,ironpython,ironruby
2009-12-28T13:30:00.000
0
1,969,472
IronPython has had more time to focus on performance improvements, but IronRuby has made significant performance improvements as of late. However, we rarely pin IronRuby up against IronPython. While people may comment here that one or the other is faster, and certain special cases/examples may even be uses to prove this, there is no exhaustive comparison available today.
0
753
true
0
1
Performance comparison between IronRuby and IronPython
1,972,630
1
1
0
7
6
0
1.2
1
I'm looking at existing python code that heavily uses Paramiko to do SSH and FTP. I need to allow the same code to work with some hosts that do not support a secure connection and over which I have no control. Is there a quick and easy way to do it via Paramiko, or do I need to step back, create some abstraction that supports both paramiko and Python's FTP libraries, and refactor the code to use this abstraction?
0
python,paramiko
2009-12-29T23:30:00.000
0
1,977,571
No, paramiko has no support for telnet or ftp -- you're indeed better off using a higher-level abstraction and implementing it twice, with paramiko and without it (with the ftplib and telnetlib modules of the Python standard library).
0
7,051
true
0
1
Does Paramiko support non-secure telnet and ftp instead of just SSH and SFTP?
1,978,007
3
3
0
0
2
1
0
0
Are their any ways to optimize Jython without resorting to profiling or significantly changing the code? Specifically are there any flags that can be passed to the compiler, or code hints in tight loops.
0
java,python,optimization,jython
2009-12-30T02:44:00.000
0
1,978,139
I know this is an old question, but I'm just putting this for completeness. You can use:-J-server flag to launch Jython in the Java server mode, which can help speed up the hot loops. (JVM will look to aggressively optimize, but might slow up the start up time)
0
707
false
0
1
Jython Optimizations
6,481,974
3
3
0
1
2
1
1.2
0
Are their any ways to optimize Jython without resorting to profiling or significantly changing the code? Specifically are there any flags that can be passed to the compiler, or code hints in tight loops.
0
java,python,optimization,jython
2009-12-30T02:44:00.000
0
1,978,139
Jython compiler does not offer lots of optimization choices. However, since the Java virtual machine (java) and perhaps compiler (javac) are getting invoked in the back end or at runtime, you should take a look at them. Java has different runtime switches to use depending on whether you are going to launch it as a server process, client process, etc. You can also tell how much memory to allocate too.
0
707
true
0
1
Jython Optimizations
1,990,415
3
3
0
6
2
1
1
0
Are their any ways to optimize Jython without resorting to profiling or significantly changing the code? Specifically are there any flags that can be passed to the compiler, or code hints in tight loops.
0
java,python,optimization,jython
2009-12-30T02:44:00.000
0
1,978,139
No flags, no code hints. You can optimize by tweaking your code much as you would for any other Python implementation (hoisting, etc), but profiling helps by telling you where it's worth your while to expend such effort -- so, sure, you can optimize "without resorting to profiling" (and the code changes to do so may well be deemed to be not significant), but you're unlikely to guess right about where your time and energy are best spent, while profiling helps you determine exactly that.
0
707
false
0
1
Jython Optimizations
1,978,207
5
8
0
1
4
1
0.024995
0
A friend was "burned" when starting to learn Python, and now sees the language as perhaps fatally flawed. He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" to figure out what was wrong. His objection to Python is thus that it allows one to accidentally add attributes to an object. Unit tests don't provide a solution to this. One doesn't write unit tests against an API being used. One may have a mock for the class, but the mock could have the same typo or incorrect assumption about the attribute name. It's possible to use __setattr__() to guard against this, but (as far as I know), no one does. The only thing I've been able to tell my friend is that after several years of writing Python code full-time, I don't recall ever being burned by this. What else can I tell him?
0
python,attributes
2009-12-30T16:59:00.000
0
1,981,208
I think your friend has misplaced his frustration in the language. His real problem is lack of debugging techniques. teach him how to break down a program into small pieces to examine the output. like a manual unit test, this way any inconsistency is found and any assumptions are proven or discarded.
0
521
false
0
1
Protection from accidentally misnaming object attributes in Python?
1,981,378
5
8
0
0
4
1
0
0
A friend was "burned" when starting to learn Python, and now sees the language as perhaps fatally flawed. He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" to figure out what was wrong. His objection to Python is thus that it allows one to accidentally add attributes to an object. Unit tests don't provide a solution to this. One doesn't write unit tests against an API being used. One may have a mock for the class, but the mock could have the same typo or incorrect assumption about the attribute name. It's possible to use __setattr__() to guard against this, but (as far as I know), no one does. The only thing I've been able to tell my friend is that after several years of writing Python code full-time, I don't recall ever being burned by this. What else can I tell him?
0
python,attributes
2009-12-30T16:59:00.000
0
1,981,208
I had a similar bad experience with Python when I first started ... took me 3 months to get over it. Having a tool which warns would be nice back then ...
0
521
false
0
1
Protection from accidentally misnaming object attributes in Python?
1,981,269
5
8
0
5
4
1
0.124353
0
A friend was "burned" when starting to learn Python, and now sees the language as perhaps fatally flawed. He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" to figure out what was wrong. His objection to Python is thus that it allows one to accidentally add attributes to an object. Unit tests don't provide a solution to this. One doesn't write unit tests against an API being used. One may have a mock for the class, but the mock could have the same typo or incorrect assumption about the attribute name. It's possible to use __setattr__() to guard against this, but (as far as I know), no one does. The only thing I've been able to tell my friend is that after several years of writing Python code full-time, I don't recall ever being burned by this. What else can I tell him?
0
python,attributes
2009-12-30T16:59:00.000
0
1,981,208
If the possibility to make mistakes is enough for him to consider a language "fatally flawed", I don't think you can convince him otherwise. The more you can do with a language, the more you can do wrong with the language. It's a caveat of flexibility—but that's true for any language.
0
521
false
0
1
Protection from accidentally misnaming object attributes in Python?
1,981,255
5
8
0
12
4
1
1.2
0
A friend was "burned" when starting to learn Python, and now sees the language as perhaps fatally flawed. He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" to figure out what was wrong. His objection to Python is thus that it allows one to accidentally add attributes to an object. Unit tests don't provide a solution to this. One doesn't write unit tests against an API being used. One may have a mock for the class, but the mock could have the same typo or incorrect assumption about the attribute name. It's possible to use __setattr__() to guard against this, but (as far as I know), no one does. The only thing I've been able to tell my friend is that after several years of writing Python code full-time, I don't recall ever being burned by this. What else can I tell him?
0
python,attributes
2009-12-30T16:59:00.000
0
1,981,208
"changed the value of an object's attribute" Can lead to problems. This is pretty well known. You know it, now, also. That doesn't indict the language. It simply says that you've learned an important lesson in dynamic language programming. Unit testing absolutely discovers this. You are not forced to mock all library classes. Some folks say it's only a unit test when it's tested in complete isolation. This is silly. You have to trust the library modules -- it's a feature of your architecture. Rather than mock them, just use them. (It is important to write mocks for your own newly-developed libraries. It's also important to mock libraries that make expensive API calls.) In most cases, you can (and should) test your classes with the real library modules. This will find the misspelled attribute name. Also, now that you know that attributes are dynamic, it's really easy to verify that the attribute exists. How? Use interactive Python to explore the classes before writing too much code. Remember, Python is not Java and it's not C. You can execute Python interactively and determine immediately if you've spelled something wrong. Writing a lot of code without doing any interactive confirmation is -- simply -- the wrong way to use Python. A little interactive exploration will find misspelled attribute names. Finally -- for your own classes -- you can wrap updatable attributes as properties. This makes it easier to debug any misspelled attribute names. Again, you know to check for this. You can use interactive development to confirm the attribute names. Fussing around with __setattr__ creates problems. In some cases, we actually need to add attributes to an object. Why? It's simpler than creating a whole subclass for one special case where we have to maintain more state information. Other things you can say: I was burned by a C program that absolutely could not be made to work because of ______. [Insert any known C-language problem you want here. No array bounds checking, for example] Does that make C fatally flawed? I was burned by a DBA who changed a column name and all the SQL broke. It's painful to unit test all of it. Does that make the relational database fatally flawed? I was burned by a sys admin who changed a directory's permissions and my application broke. It was nearly impossible to find. Does that make the OS fatally flawed? I was burned by a COBOL program where someone changed the copybook, forgot to recompile the program, and we couldn't debug it because the source looked perfect. COBOL, however, actually is fatally flawed, so this isn't a good example.
0
521
true
0
1
Protection from accidentally misnaming object attributes in Python?
1,981,279
5
8
0
1
4
1
0.024995
0
A friend was "burned" when starting to learn Python, and now sees the language as perhaps fatally flawed. He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" to figure out what was wrong. His objection to Python is thus that it allows one to accidentally add attributes to an object. Unit tests don't provide a solution to this. One doesn't write unit tests against an API being used. One may have a mock for the class, but the mock could have the same typo or incorrect assumption about the attribute name. It's possible to use __setattr__() to guard against this, but (as far as I know), no one does. The only thing I've been able to tell my friend is that after several years of writing Python code full-time, I don't recall ever being burned by this. What else can I tell him?
0
python,attributes
2009-12-30T16:59:00.000
0
1,981,208
He's effectively ruling out an entire class of programming languages -- dynamically-typed languages -- because of one hard lesson learned. He can use only statically-typed languages if he wishes and still have a very productive career as a programmer, but he is certainly going to have deep frustrations with them as well. Will he then conclude that they are fatally-flawed?
0
521
false
0
1
Protection from accidentally misnaming object attributes in Python?
1,981,288
1
2
0
2
0
0
1.2
0
Is there any way of writing pexpect like small program which can launch a process and pass the password to that process? I don't want to install and use pexpect python library but want to know the logic behind it so that using linux system apis I can build something similar.
0
c++,python,linux,pexpect
2009-12-30T22:06:00.000
1
1,982,788
You could just use "expect". It is very light weight and is made to do what youre describing.
0
639
true
0
1
writing pexpect like program in c++ on Linux
1,982,873
3
5
0
5
15
1
0.197375
0
Are Python docstrings and comments stored in memory when a module is loaded? I've wondered if this is true, because I usually document my code well; may this affect memory usage? Usually every Python object has a __doc__ method. Are those docstrings read from the file, or processed otherwise? I've done searches here in the forums, Google and Mailing-Lists, but I haven't found any relevant information. Do you know better?
0
python,comments,memory-management,docstring
2009-12-30T23:55:00.000
0
1,983,177
They are getting read from the file (when the file is compiled to pyc or when the pyc is loaded -- they must be available under object.__doc__) but no --> this will not significantly impact performance under any reasonable circumstances, or are you really writing multi-megabyte doc-strings?
0
3,713
false
0
1
Are Python docstrings and comments stored in memory when a module is loaded?
1,983,193
3
5
0
12
15
1
1
0
Are Python docstrings and comments stored in memory when a module is loaded? I've wondered if this is true, because I usually document my code well; may this affect memory usage? Usually every Python object has a __doc__ method. Are those docstrings read from the file, or processed otherwise? I've done searches here in the forums, Google and Mailing-Lists, but I haven't found any relevant information. Do you know better?
0
python,comments,memory-management,docstring
2009-12-30T23:55:00.000
0
1,983,177
Yes the docstrings are read from the file, but that shouldn't stop you writing them. Never ever compromise readability of code for performance until you have done a performance test and found that the thing you are worried about is in fact the bottleneck in your program that is causing a problem. I would think that it is extremely unlikely that a docstring will cause any measurable performance impact in any real world situation.
0
3,713
false
0
1
Are Python docstrings and comments stored in memory when a module is loaded?
1,983,203
3
5
0
1
15
1
0.039979
0
Are Python docstrings and comments stored in memory when a module is loaded? I've wondered if this is true, because I usually document my code well; may this affect memory usage? Usually every Python object has a __doc__ method. Are those docstrings read from the file, or processed otherwise? I've done searches here in the forums, Google and Mailing-Lists, but I haven't found any relevant information. Do you know better?
0
python,comments,memory-management,docstring
2009-12-30T23:55:00.000
0
1,983,177
Do Python docstrings and comments are stored in memory when module is loaded? Docstrings are compiled into the .pyc file, and are loaded into memory. Comments are discarded during compilation and have no impact on anything except the insignificant extra time taken to ignore them during compilation (which happens once only after any change to a .py file, except for the main script which is re-compiled every time it is run). Also note that these strings are preserved only if they are the first thing in the module, class definition, or function definition. You can include additional strings pretty much anywhere, but they will be discarded during compilation just as comments are.
0
3,713
false
0
1
Are Python docstrings and comments stored in memory when a module is loaded?
1,983,288
4
6
0
14
16
1
1
0
All the books I've read on data structures so far seem to use C/C++, and make heavy use of the "manual" pointer control that they offer. Since Python hides that sort of memory management and garbage collection from the user is it even possible to implement efficient data structures in this language, and is there any reason to do so instead of using the built-ins?
0
python,data-structures
2009-12-31T19:10:00.000
0
1,986,712
For some simple data structures (eg. a stack), you can just use the builtin list to get your job done. With more complex structures (eg. a bloom filter), you'll have to implement them yourself using the primitives the language supports. You should use the builtins if they serve your purpose really since they're debugged and optimised by a horde of people for a long time. Doing it from scratch by yourself will probably produce an inferior data structure. If however, you need something that's not available as a primitive or if the primitive doesn't perform well enough, you'll have to implement your own type. The details like pointer management etc. are just implementation talk and don't really limit the capabilities of the language itself.
0
22,283
false
0
1
Data Structures in Python
1,986,739
4
6
0
2
16
1
0.066568
0
All the books I've read on data structures so far seem to use C/C++, and make heavy use of the "manual" pointer control that they offer. Since Python hides that sort of memory management and garbage collection from the user is it even possible to implement efficient data structures in this language, and is there any reason to do so instead of using the built-ins?
0
python,data-structures
2009-12-31T19:10:00.000
0
1,986,712
With Python you have access to a vast assortment of library modules written and debugged by other people. Odds are very good that somewhere out there, there is a module that does at least part of what you want, and odds are even good that it might be implemented in C for performance. For example, if you need to do matrix math, you can use NumPy, which was written in C and Fortran. Python is slow enough that you won't be happy if you try to write some sort of really compute-intensive code (example, a Fast Fourier Transform) in native Python. On the other hand, you can get a C-coded Fourier Transform as part of SciPy, and just use it. I have never had a situation where I wanted to solve a problem in Python and said "darn, I just can't express the data structure I need." If you are a pioneer, and you are doing something in Python for which there just isn't any library module out there, then you can try writing it in pure Python. If it is fast enough, you are done. If it is too slow, you can profile it, figure out where the slow parts are, and rewrite them in C using the Python C API. I have never needed to do this yet.
0
22,283
false
0
1
Data Structures in Python
1,987,211
4
6
0
0
16
1
0
0
All the books I've read on data structures so far seem to use C/C++, and make heavy use of the "manual" pointer control that they offer. Since Python hides that sort of memory management and garbage collection from the user is it even possible to implement efficient data structures in this language, and is there any reason to do so instead of using the built-ins?
0
python,data-structures
2009-12-31T19:10:00.000
0
1,986,712
It's not possible to implement something like a C++ vector in Python, since you don't have array primitives the way C/C++ do. However, anything more complicated can be implemented (efficiently) on top of it, including, but not limited to: linked lists, hash tables, multisets, bloom filters, etc.
0
22,283
false
0
1
Data Structures in Python
1,986,761
4
6
0
10
16
1
1
0
All the books I've read on data structures so far seem to use C/C++, and make heavy use of the "manual" pointer control that they offer. Since Python hides that sort of memory management and garbage collection from the user is it even possible to implement efficient data structures in this language, and is there any reason to do so instead of using the built-ins?
0
python,data-structures
2009-12-31T19:10:00.000
0
1,986,712
C/C++ data structure books are only attempting to teach you the underlying principles behind the various structures - they are generally not advising you to actually go out and re-invent the wheel by building your own library of stacks and lists. Whether you're using Python, C++, C#, Java, whatever, you should always look to the built in data structures first. They will generally be implemented using the same system primitives you would have to use doing it yourself, but with the advantage of having been tried and tested. Only when the provided data structures do not allow you to accomplish what you need, and there isn't an alternative and reliable library available to you, should you be looking at building something from scratch (or extending what's provided).
0
22,283
false
0
1
Data Structures in Python
1,986,749
1
4
0
10
0
0
1.2
0
Please bear with me experts i'm a newbie in web dev. With html,css can take care of webpages.. javascript,ajax for some dynamic content.. php for server side scripting,accessing databases,sending emails,doing all other stuf... What role do these programming languages play? Can they do any other important task which cannot be done by PHP?
0
c++,python,c,perl
2010-01-02T09:14:00.000
0
1,991,065
All languages can all do basically any task any other one of them can do, as they are all Turing complete. PHP works as a server-side scripting language, but you can also use Perl, Python, Ruby, Haskell, Lisp, Java, C, C++, assembly, or pretty much any other language that can access standard input and standard output for CGI communication with web content. PHP is widely used because a) it's easy to learn a little and go, and b) the rather tedious CGI protocols are skipped, as the language handles them for you, so you can just plug your PHP script into an HTML page and not have to know how your program reads the information at all. This makes web programming easier for PHP, but the PHP interpreter is written in C, which does all the heavy lifting, so logically if PHP can do server-side scripting, so can C. Since most other languages are written in C, they too can do server-side scripting. (And since C compiles down to assembly, assembly can do it too, and so can any language that compiles down to assembly. Which is all of them not already covered.)
0
719
true
1
1
Role of C,C++,python,perl in Web development
1,991,076
1
1
0
2
1
0
1.2
0
I have a simple setup with my python libraries in /domains/somedomain.com/libs/ and all my tests run fine. I start WSGI with DJANGO_SETTINGS_MODULE to "somedomain.settings" where somedomain is a package in libs/ Suddenly, when adding pywapi.py into libs/ I can't import it when hitting the site. But, if I add 'import pywapi' to my wsgi script, it fails when hit by Apache, but succeeds if I just write it. the WSGI itself is actually adding libs/ to the path, so I know it should be there when running. The path is absolute, too, so any change in CWD shouldn't be causing this. I can't think of anything else and I've been tinkering with it half of my otherwise productive morning.
0
python,django,apache,mod-wsgi
2010-01-02T14:29:00.000
0
1,991,743
I think the problem is related with the permissions of that file. Check that the user running wsgi (apache user, usually) is capable of reading and writing the everything in the libs folder and specially capable of reading the file pywapi.py.
0
927
true
1
1
How does Django + mod_wsgi affect the python path?
1,991,778
1
3
0
0
2
0
0
1
I want to upload a file from my computer to a file hoster like hotfile.com via a Python script. Because Hotfile is only offering a web-based upload service (no ftp). I need Python first to login with my username and password and after that to upload the file. When the file transfer is over, I need the Download and Delete-link (which is generated right after the Upload has finished). Is this even possible? If so, can anybody tell me how the script looks like or even give my hints how to build it? Thanks
0
python,authentication,file-upload,automation
2010-01-02T22:14:00.000
0
1,993,060
You mention they do not offer FTP, but I went to their site and found the following: How to upload with FTP? ftp.hotfile.com user: your hotfile username pass: your hotfile password You can upload and make folders, but cant rename,move files Try it. If it works, using FTP from within Python will be a very simple task.
0
7,457
false
0
1
Upload file to a website via Python script
1,993,139
1
6
0
5
143
0
0.16514
0
Python seems to have functions for copying files (e.g. shutil.copy) and functions for copying directories (e.g. shutil.copytree) but I haven't found any function that handles both. Sure, it's trivial to check whether you want to copy a file or a directory, but it seems like a strange omission. Is there really no standard function that works like the unix cp -r command, i.e. supports both directories and files and copies recursively? What would be the most elegant way to work around this problem in Python?
0
python
2010-01-03T10:06:00.000
1
1,994,488
shutil.copy and shutil.copy2 are copying files. shutil.copytree copies a folder with all the files and all subfolders. shutil.copytree is using shutil.copy2 to copy the files. So the analog to cp -r you are saying is the shutil.copytree because cp -r targets and copies a folder and its files/subfolders like shutil.copytree. Without the -r cp copies files like shutil.copy and shutil.copy2 do.
0
192,392
false
0
1
Copy file or directories recursively in Python
42,249,637
1
2
0
0
1
1
0
0
Is it possible for a python script to execute at a low run level? Edit: To clarify, is it possible for a python script to run in the background, kind of like a daemon.
0
python,runlevel
2010-01-03T14:21:00.000
1
1,995,102
Yes. The scripts that control daemons are (normally) plain old bash scripts and can run whatever a bash script can run. The only difference is that in a low runlevel, lots of other system services will not be running, so if the program tries to do something that depends on another daemon, that may fail.
0
523
false
0
1
Python execution
1,996,354
4
10
0
4
71
1
0.07983
0
Just about everyone uses them, but many, including me simply take it for granted that they just work. I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me. Now, C++ is probably a good place to start since you can throw anything in that language. Also, C is close to assembly. How would one emulate exceptions using pure C constructs and no assembly? Finally, I heard a rumor that Google employees do not use exceptions for some projects due to speed considerations. Is this just a rumor? How can anything substantial be accomplished without them? Thank you.
0
c++,python,c,exception
2010-01-03T18:06:00.000
0
1,995,734
The key thing an exception implementation needs to handle is how to return to the exception handler once an exception has been thrown. Since you may have made an arbitrary number of nested function calls since the try statement in C++, it must unwind the call stack searching for the handler. However implemented, this must incur the code size cost of maintaining sufficient information in order to perform this operation (and generally means a table of data for calls that can take exceptions). It also means that the dynamic code execution path will be longer than simply returning from functions calls (which is a fairly inexpensive operation on most platforms). There may be other costs as well depending on the implementation. The relative cost will vary depending on the language used. The higher-level language used, the less likely the code size cost will matter, and the information may be retained regardless of whether exceptions are used. An application where the use of exceptions (and C++ in general) is often avoided for good reasons is embedded firmware. In typical small bare metal or RTOS platforms, you might have 1MB of code space, or 64K, or even smaller. Some platforms are so small, even C is not practical to use. In this kind of environment, the size impact is relevant because of the cost mentioned above. It also impacts the standard library itself. Embedded toolchain vendors will often produce a library without exception capability, which has a huge impact on code size. Highly optimizing compilers may also analyze the callgraph and optimize away needed call frame information for the unwind operation for considerable space reduction. Exceptions also make it more difficult to analyze hard real-time requirements. In more typical environments, the code size cost is almost certainly irrelevant and the performance factor is likely key. Whether you use them will depend on your performance requirements and how you want to use them. Using exceptions in non-exceptional cases can make an elegant design, but at a performance cost that may be unacceptable for high performance systems. Implementations and relative cost will vary by platform and compiler, so the best way to truly understand if exceptions are a problem is to analyze your own code's performance.
0
9,676
false
0
1
How are exceptions implemented under the hood?
1,996,011
4
10
0
49
71
1
1.2
0
Just about everyone uses them, but many, including me simply take it for granted that they just work. I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me. Now, C++ is probably a good place to start since you can throw anything in that language. Also, C is close to assembly. How would one emulate exceptions using pure C constructs and no assembly? Finally, I heard a rumor that Google employees do not use exceptions for some projects due to speed considerations. Is this just a rumor? How can anything substantial be accomplished without them? Thank you.
0
c++,python,c,exception
2010-01-03T18:06:00.000
0
1,995,734
Exceptions are just a specific example of a more general case of advanced non-local flow control constructs. Other examples are: notifications (a generalization of exceptions, originally from some old Lisp object system, now implemented in e.g. CommonLisp and Ioke), continuations (a more structured form of GOTO, popular in high-level, higher-order languages), coroutines (a generalization of subroutines, popular especially in Lua), generators à la Python (essentially a restricted form of coroutines), fibers (cooperative light-weight threads) and of course the already mentioned GOTO. (I'm sure there's many others I missed.) An interesting property of these constructs is that they are all roughly equivalent in expressive power: if you have one, you can pretty easily build all the others. So, how you best implement exceptions depends on what other constructs you have available: Every CPU has GOTO, therefore you can always fall back to that, if you must. C has setjmp/longjmp which are basically MacGyver continuations (built out of duct-tape and toothpicks, not quite the real thing, but will at least get you out of the immediate trouble if you don't have something better available). The JVM and CLI have exceptions of their own, which means that if the exception semantics of your language match Java's/C#'s, you are home free (but if not, then you are screwed). The Parrot VM as both exceptions and continuations. Windows has its own framework for exception handling, which language implementors can use to build their own exceptions on top. A very interesting use case, both of the usage of exceptions and the implementation of exceptions is Microsoft Live Lab's Volta Project. (Now defunct.) The goal of Volta was to provide architectural refactoring for Web applications at the push of a button. So, you could turn your one-tier web application into a two- or three-tier application just by putting some [Browser] or [DB] attributes on your .NET code and the code would then automagically run on the client or in the DB. In order to do that, the .NET code had to be translated to JavaScript source code, obviously. Now, you could just write an entire VM in JavaScript and run the bytecode unmodified. (Basically, port the CLR from C++ to JavaScript.) There are actually projects that do this (e.g. the HotRuby VM), but this is both inefficient and not very interoperable with other JavaScript code. So, instead, they wrote a compiler which compiles CIL bytecode to JavaScript sourcecode. However, JavaScript lacks certain features that .NET has (generators, threads, also the two exception models aren't 100% compatible), and more importantly it lacks certain features that compiler writers love (either GOTO or continuations) and that could be used to implement the above-mentioned missing features. However, JavaScript does have exceptions. So, they used JavaScript Exceptions to implement Volta Continuations and then they used Volta Continuations to implement .NET Exceptions, .NET Generators and even .NET Managed Threads(!!!) So, to answer your original question: How are exceptions implemented under the hood? With Exceptions, ironically! At least in this very specific case, anyway. Another great example is some of the exception proposals on the Go mailing list, which implement exceptions using Goroutines (something like a mixture of concurrent coroutines ans CSP processes). Yet another example is Haskell, which uses Monads, lazy evaluation, tail call optimization and higher-order functions to implement exceptions. Some modern CPUs also support basic building blocks for exceptions (for example the Vega-3 CPUs that were specifically designed for the Azul Systems Java Compute Accelerators).
0
9,676
true
0
1
How are exceptions implemented under the hood?
1,995,979
4
10
0
1
71
1
0.019997
0
Just about everyone uses them, but many, including me simply take it for granted that they just work. I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me. Now, C++ is probably a good place to start since you can throw anything in that language. Also, C is close to assembly. How would one emulate exceptions using pure C constructs and no assembly? Finally, I heard a rumor that Google employees do not use exceptions for some projects due to speed considerations. Is this just a rumor? How can anything substantial be accomplished without them? Thank you.
0
c++,python,c,exception
2010-01-03T18:06:00.000
0
1,995,734
Regarding performance - sparse use of exceptions will probably have negligible effects, but do not abuse them. I have personally seen Java code which performed two orders of magnitude worse than it could have (took about x100 the time) because exceptions were used in an important loop instead of more standard if/returns.
0
9,676
false
0
1
How are exceptions implemented under the hood?
1,995,769
4
10
0
5
71
1
0.099668
0
Just about everyone uses them, but many, including me simply take it for granted that they just work. I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me. Now, C++ is probably a good place to start since you can throw anything in that language. Also, C is close to assembly. How would one emulate exceptions using pure C constructs and no assembly? Finally, I heard a rumor that Google employees do not use exceptions for some projects due to speed considerations. Is this just a rumor? How can anything substantial be accomplished without them? Thank you.
0
c++,python,c,exception
2010-01-03T18:06:00.000
0
1,995,734
setjmp() and longjmp() usually. Exception catching does have a non-trivial cost, but for most purposes it's not a big deal.
0
9,676
false
0
1
How are exceptions implemented under the hood?
1,995,737
1
4
0
0
44
1
0
0
What's an easy way of finding all the python modules from a particular package that are being used in an application?
0
python,package
2010-01-04T04:01:00.000
0
1,997,449
A real simple method is to delete all .pyc files from the package or folder, and then run the application. Once you've played a bit, do a directory listing and see which files have .pyc files now. Those are modules which were imported by the application. (Note: the __main__ module, whichever one you invoke as the "main" script, never gets compiled, so you should not expect to see a .pyc file for it unless something imported it from within the application. This is often a sign of a problem if it does happen.)
0
20,841
false
0
1
Find which python modules are being imported
1,997,473
1
6
0
9
34
0
1
0
So the state I'm in released a bunch of data in PDF form, but to make matters worse, most (all?) of the PDFs appear to be letters typed in Office, printed/fax, and then scanned (our government at its best eh?). At first I thought I was crazy, but then I started seeing numerous pdfs that are 'tilted', like someone didn't get them on the scanner properly. So, I figured the next best thing to getting the actual text out of them, would be to turn each page into an image. Obviously this needs to be automated, and I'd prefer to stick with Python if possible. If Ruby or Perl have some form of implementation that's just too awesome to pass up, I can go that route. I've tried pyPDF for text extraction, that obviously didn't do me much good. I've tried swftools, but the images I'm getting from that are just shy of completely unusable. It just seems like the fonts get ruined in the conversion. I also don't even really care about the image format on the way out, just as long as they're relatively lightweight, and readable.
0
python,pdf,image
2010-01-04T20:33:00.000
0
2,002,055
You could call e.g. pdftoppm from the command-line (or using Python's subprocess module) and then convert the resulting PPM files to the desired format using e.g. ImageMagick (again, using subprocess or some bindings if they exist).
0
70,011
false
1
1
Converting PDF to images automatically
2,002,436
1
1
0
3
1
0
1.2
0
I have a Python CGI handling a payment transaction. When the user submits the form, the CGI is called. After submission, the CGI takes a while to perform the credit card transaction. During that time, a user might hit the ESC or refresh button. Doing that will not "kill" the CGI, meaning, the script will keep running completing the transaction but the CGI's HTML output will never reach the client. This means the user will not know the transaction was completed. How can I solve this problem?
0
python,cgi
2010-01-04T20:57:00.000
0
2,002,180
Same as you should do with every POST: don't send output, but put the output in a session variable and redirect to a pure-GET request. This one looks in the session for messages, and clears+displays those.
0
262
true
1
1
Python CGI transaction
2,002,206
1
4
0
1
8
0
0.049958
0
I'm working on a c++ project, and we recently needed to include a small part of boost in it. The boost part is really minimal (Boost::Python), thus, using bjam to build everything looks like an overkill (besides, everyone working on the project feels comfortable with make, and has no knowloedge of jam). I made quite some tests already, but I cant find a way to include the formerly mentioned library in my makefile and make the build succesful. All your help is deeply apreciated. :)
0
c++,boost,build-process,makefile,boost-python
2010-01-05T01:12:00.000
0
2,003,506
Run bjam from the makefile, just for building that part
0
2,460
false
0
1
How to build a boost dependent project using regular makefiles?
2,003,592
1
2
0
2
4
0
0.197375
0
I want to remove as much complexity as I can from administering Python in on Amazon EC2 following some truly awful experiences with hosting providers who claim support for Python. I am looking for some guidance on which AMI to choose so that I have a stable and easily managed environment which already included Python and ideally an Apache web server and a database. I am agnostic to Python version, web server, DB and OS as I am still early enough in my development cycle that I can influence those choices. Cost is not a consideration (within bounds) so Windows will work fine if it means easy administration. Anyone have any practical experience or recommendations they can share?
0
python,amazon-ec2
2010-01-05T18:01:00.000
0
2,008,055
If you can get by with using the Amazon provided ones, I'd recommend it. I tend to use ami-84db39ed. Honestly though, if you plan on leaving this running all the time, you would probably save a bit of money by just going with a VPS. Amazon tends to be cheaper if you are turning the service on and off over time.
0
2,510
false
0
1
Can you recommend an Amazon AMI for Python?
2,008,170
1
1
0
1
1
0
1.2
1
I have a need to display some basic info about a facebook group on a website i am building. All i am really looking to show is the total number of members, and maybe a list of the few most recent people who joined. I would like to not have to login to FB to accomplish this, is there an API for groups that allows anonymous access? or do i have to go the screen scraping route?
0
python,django,facebook
2010-01-05T20:23:00.000
0
2,008,816
Use the Python Facebook module on Google Code.
0
342
true
0
1
Python + Facebook, getting info about a group easily
2,012,448
3
5
0
4
24
1
0.158649
0
I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons of different directories, this can take around 5 seconds -- all to run a script that might fail instantly. Do folks have suggestions for how to speed up this process? For instance, one hack I've seen is to set the LD_PRELOAD_32 environment variable to a library that caches the result of ENOENT calls (e.g. failed stat() calls) between runs. Of course, this has all sorts of problems (potentially confusing non-python programs, negative caching, etc.).
0
python
2010-01-06T00:47:00.000
0
2,010,255
The first things that come to mind are: Try a smaller path Make sure your modules are pyc's so they'll load faster Make sure you don't double import, or import too much Other than that, are you sure that the disk operations are what's bogging you down? Is your disk/operating system really busy or old and slow? Maybe a defrag is in order?
0
12,690
false
0
1
Speeding up the python "import" loader
2,010,309
3
5
0
1
24
1
0.039979
0
I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons of different directories, this can take around 5 seconds -- all to run a script that might fail instantly. Do folks have suggestions for how to speed up this process? For instance, one hack I've seen is to set the LD_PRELOAD_32 environment variable to a library that caches the result of ENOENT calls (e.g. failed stat() calls) between runs. Of course, this has all sorts of problems (potentially confusing non-python programs, negative caching, etc.).
0
python
2010-01-06T00:47:00.000
0
2,010,255
Something's missing from your premise--I've never seen some "more-or-less" basic modules take over a second to import, and I'm not running Python on what I would call cutting-edge hardware. Either you're running on some seriously old hardware, or you're running on an overloaded machine, or either your OS or Python installation is broken in some way. Or you're not really importing "basic" modules. If it's any of the first three issues, you need to look at the root problem for a solution. If it's the last, we really need to know what the specific packages are to be of any help.
0
12,690
false
0
1
Speeding up the python "import" loader
2,010,759
3
5
0
11
24
1
1
0
I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons of different directories, this can take around 5 seconds -- all to run a script that might fail instantly. Do folks have suggestions for how to speed up this process? For instance, one hack I've seen is to set the LD_PRELOAD_32 environment variable to a library that caches the result of ENOENT calls (e.g. failed stat() calls) between runs. Of course, this has all sorts of problems (potentially confusing non-python programs, negative caching, etc.).
0
python
2010-01-06T00:47:00.000
0
2,010,255
zipping up as many pyc files as feasible (with proper directory structure for packages), and putting that zipfile as the very first entry in sys.path (on the best available local disk, ideally) can speed up startup times a lot.
0
12,690
false
0
1
Speeding up the python "import" loader
2,010,354
1
7
0
0
6
0
0
1
How do I get the MAC address of a remote host on my LAN? I'm using Python and Linux.
0
python,linux,networking,mac-address
2010-01-06T03:40:00.000
1
2,010,816
Many years ago, I was tasked with gathering various machine info from all machines on a corporate campus. One desired piece of info was the MAC address, which is difficult to get on a network that spanned multiple subnets. At the time, I used the Windows built-in "nbtstat" command. Today there is a Unix utility called "nbtscan" that provides similar info. If you do not wish to use an external tool, maybe there are NetBIOS libraries for python that could be used to gather the info for you?
0
22,526
false
0
1
Get remote MAC address using Python and Linux
2,010,975
2
5
0
0
1
0
0
0
i am facing some problem with files with huge data. i need to skip doing some execution on those files. i get the data of the file into a variable. now i need to get the byte of the variable and if it is greater than 102400 , then print a message. update : i cannot open the files , since it is present in a tar file. the content is already getting copied to a variable called 'data' i am able to print contents of the variable data. i just need to check if it has more than 102400 bytes. thanks
0
python,tar
2010-01-07T12:45:00.000
1
2,020,318
This answer seems irrelevant, since I seem to have misunderstood the question, which has now been clarified. However, should someone find this question, while searching with pretty much the same terms, this answer may still be relevant: Just open the file in binary mode f = open(filename, 'rb') read/skip a bunch and print the next byte(s). I used the same method to 'fix' the n-th byte in a zillion images once.
0
1,889
false
0
1
how do i get the byte count of a variable in python just like wc -c gives in unix
2,020,334
2
5
0
1
1
0
0.039979
0
i am facing some problem with files with huge data. i need to skip doing some execution on those files. i get the data of the file into a variable. now i need to get the byte of the variable and if it is greater than 102400 , then print a message. update : i cannot open the files , since it is present in a tar file. the content is already getting copied to a variable called 'data' i am able to print contents of the variable data. i just need to check if it has more than 102400 bytes. thanks
0
python,tar
2010-01-07T12:45:00.000
1
2,020,318
len(data) gives you the size in bytes if it's binary data. With strings the size depends on the encoding used.
0
1,889
false
0
1
how do i get the byte count of a variable in python just like wc -c gives in unix
2,020,425
1
1
0
2
2
0
1.2
0
i'm stress testing 2 different projects: one is proxsmtpd - smtp proxy written in C And the other one, smtp_proxy.py, which i developed under 1 hour, with use of asyncore and smtpd python modules. I stressed both projects under heavy load, and found out that proxsmtpd is able to hold 400 smtp sessions / sec, while my python program, is able to do only 160 smtp sessions /sec. So, my question is, does it because there are some performance limitations in asyncore, or C programs are just faster? Or maybe it's me, using asyncore in inefficient way?
0
python,proxy,smtp,asyncore,smtpd
2010-01-07T17:25:00.000
0
2,022,211
I think it's a fair assumption that given a good C version and a good Python version, the C version will be faster and more scalable but in your case, you might want to run a profiler and see why and where your program is not scaling up as much as the C version. Perhaps you can uncover the tight spots and optimise it to squeeze some more performance out of your code. Also, I don't know much about asyncore but the first Python library people seem to gravitate towards when they want to do async stuff is twisted. So, perhaps there is a performance improvement there.
0
694
true
0
1
Python asyncore vs plain old C
2,022,273
1
1
0
0
1
0
1.2
0
I'm trying to write a simple command line audio player using the Python Gstreamer bindings. Is there a function in the gstreamer API that determines in advance whether or not a particular file (URI) can be decoded and played by the currently installed set of codecs?
0
python,uri,decode,gstreamer,codec
2010-01-08T06:49:00.000
1
2,025,964
I guess you can try to play it and see if that raises any error - in fact, there's no way to know the set of codecs necessary without opening the file. Some distributions even have hooks in place that ask the user to download the right codec when you start playing something.
0
208
true
0
1
How do you ask gstreamer if a file can be played?
2,026,830
2
4
0
1
7
0
0.049958
0
If you were looking to hire a web developer who would primarily be working with TurboGears/Python - what sort of questions should you ask them?
0
python,turbogears
2010-01-09T17:07:00.000
0
2,034,128
Don't quiz. Get some real (possibly broken) code from you vcs. Get them to tell you how they would fix it / add a feature. If they can, ask them to bring some samples of previous work.
0
2,484
false
0
1
Good interview questions for a Python/TurboGears web developer?
2,035,944
2
4
0
1
7
0
0.049958
0
If you were looking to hire a web developer who would primarily be working with TurboGears/Python - what sort of questions should you ask them?
0
python,turbogears
2010-01-09T17:07:00.000
0
2,034,128
Ask him for: Instrospection Model-View-Control design Documenting tools If he know a lot about that, surely know a lot about other issues.
0
2,484
false
0
1
Good interview questions for a Python/TurboGears web developer?
2,034,217
2
15
0
2
30
0
0.02666
0
Is there any web-based IDE that I can use to run quick tests? There're a dozen for PHP and some for even Java but I haven't found yet that runs Python. If there's an open-source IDE available that I can host and run myself, that'd be better. Thanks
0
python,testing,ide
2010-01-10T12:25:00.000
0
2,036,987
Repl.it has a python interpreter and terminal among others. It may not be a full-fledged IDE. I'm not sure how you define that.
0
30,513
false
0
1
Online IDE for Python
10,032,718
2
15
0
1
30
0
0.013333
0
Is there any web-based IDE that I can use to run quick tests? There're a dozen for PHP and some for even Java but I haven't found yet that runs Python. If there's an open-source IDE available that I can host and run myself, that'd be better. Thanks
0
python,testing,ide
2010-01-10T12:25:00.000
0
2,036,987
I'm pretty sure that IDE's are the last kind of programs that will ever go web based, because a good IDE needs to be so extremely interactive if it wants to be good. I really don't see a reason for this and others seem to agree because there isn't any. And no, an interactive web shell or compiler has nothing to do with an IDE.
0
30,513
false
0
1
Online IDE for Python
2,037,081
1
12
0
0
8
0
0
1
Often times I want to automate http queries. I currently use Java(and commons http client), but would probably prefer a scripting based approach. Something really quick and simple. Where I can set a header, go to a page and not worry about setting up the entire OO lifecycle, setting each header, calling up an html parser... I am looking for a solution in ANY language, preferable scripting
0
python,ruby,perl,http,scripting
2010-01-11T16:15:00.000
0
2,043,058
What about using PHP+Curl, or just bash?
0
4,483
false
1
1
Scripting HTTP more effeciently
2,043,069
1
1
0
2
2
0
1.2
0
I have a sign up process that is in a legacy framework and we are trying to switch to a new framework...in fact a different language. So let's say that there are 3 steps in the sign up process and each of those 3 steps has it's own file(step1.php, step2.php, step3.php). Now if I want to change page2.php to a python file I will still need the session information from page1.php. How can I transfer this information between the two pages while maintaining a valid session and obviously security. We want to integrate this language switch in the same repository as the original one and doing releases of the new changes. So that's the agile part. (I'm still not sold that this is the best way to do it but I'm more curious)
0
php,python,session
2010-01-11T21:36:00.000
0
2,045,131
In PHP, store the session information in a database, encoded in JSON. In Python, pull the session ID from the cookie and look up the session information in the database.
0
575
true
1
1
Pass session information from php to python securely? (in agile)
2,045,154
6
7
0
2
31
0
0.057081
0
How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts. For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes. Right now my approach is: Write file contents to a temp file in same directory Delete old file Rename temp file to old filename. Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed? Do these programming languages (python and java) offer constructs to lock and avoid this situation?
0
java,python,file,file-io
2010-01-12T13:36:00.000
1
2,049,247
In Linux, Solaris, Unix this is easy. Just use rename() from your program or mv. The files need to be on the same filesystem. On Windows, this is possible if you can control both programs. LockFileEx. For reads, open a shared lock on the lockfile. For writes, open an exclusive lock on the lockfile. Locking is weird in Windows, so I recommend using a separate lock file for this.
0
15,100
false
0
1
Atomic file write operations (cross platform)
4,406,823
6
7
0
13
31
0
1.2
0
How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts. For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes. Right now my approach is: Write file contents to a temp file in same directory Delete old file Rename temp file to old filename. Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed? Do these programming languages (python and java) offer constructs to lock and avoid this situation?
0
java,python,file,file-io
2010-01-12T13:36:00.000
1
2,049,247
AFAIK no. And the reason is that for such an atomic operation to be possible, there has to be OS support in the form of a transactional file system. And none of the mainstream operating system offer a transactional file system. EDIT - I'm wrong for POSIX-compliant systems at least. The POSIX rename syscall performs an atomic replace if a file with the target name already exists ... as pointed out by @janneb. That should be sufficient to do the OP's operation atomically. However, the fact remains that the Java File.renameTo() method is explicitly not guaranteed to be atomic, so it does not provide a cross-platform solution to the OP's problem. EDIT 2 - With Java 7 you can use java.nio.file.Files.move(Path source, Path target, CopyOption... options) with copyOptions and ATOMIC_MOVE. If this is not supported (by the OS / file system) you should get an exception.
0
15,100
true
0
1
Atomic file write operations (cross platform)
2,049,282
6
7
0
6
31
0
1
0
How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts. For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes. Right now my approach is: Write file contents to a temp file in same directory Delete old file Rename temp file to old filename. Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed? Do these programming languages (python and java) offer constructs to lock and avoid this situation?
0
java,python,file,file-io
2010-01-12T13:36:00.000
1
2,049,247
At least on POSIX platforms, leave out step 3 (delete old file). In POSIX, rename within a filesystem is guaranteed to be atomic, and renaming on top of an existing file replaces it atomically.
0
15,100
false
0
1
Atomic file write operations (cross platform)
2,049,334
6
7
0
1
31
0
0.028564
0
How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts. For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes. Right now my approach is: Write file contents to a temp file in same directory Delete old file Rename temp file to old filename. Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed? Do these programming languages (python and java) offer constructs to lock and avoid this situation?
0
java,python,file,file-io
2010-01-12T13:36:00.000
1
2,049,247
You could try and use an extra file to act as a lock, but I'm not sure if that will work out ok. (It would force you to create lock-checking and retry logic at both sides, java and python) Another solution might be to not create files at all, maybe you could make your java process listen on a port and serve data from there rather than from a file?
0
15,100
false
0
1
Atomic file write operations (cross platform)
2,049,333
6
7
0
3
31
0
0.085505
0
How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts. For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes. Right now my approach is: Write file contents to a temp file in same directory Delete old file Rename temp file to old filename. Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed? Do these programming languages (python and java) offer constructs to lock and avoid this situation?
0
java,python,file,file-io
2010-01-12T13:36:00.000
1
2,049,247
It's a classic producer/consumer problem. You should be able to solve this by using file renaming, which is atomic on POSIX systems.
0
15,100
false
0
1
Atomic file write operations (cross platform)
2,049,395
6
7
0
1
31
0
0.028564
0
How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts. For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes. Right now my approach is: Write file contents to a temp file in same directory Delete old file Rename temp file to old filename. Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed? Do these programming languages (python and java) offer constructs to lock and avoid this situation?
0
java,python,file,file-io
2010-01-12T13:36:00.000
1
2,049,247
Have the python scripts request permission from the service. While the service is writing it would place a lock on the file. If the lock exists, the service would reject the python request.
0
15,100
false
0
1
Atomic file write operations (cross platform)
2,049,386
1
2
0
2
3
0
1.2
0
I'm writing a curses application in Python under UNIX. I want to enable the user to use C-Y to yank from a kill ring a la Emacs. The trouble is, of course, that C-Y is caught by my shell which then sends SIGTSTP to my process. In addition, C-Z also results in SIGTSTP being sent, so catching the signal means that C-Y and C-Z are not distinguishable (though even without this the only solutions I can think of are extremely hackish). I know what I'm asking is possible (in C if not in Python), since Emacs does it. How can I disable the shell's special handling of certain control characters sent from the keyboard and have the characters in question appear on the process' stdin?
0
python,unix,signals,curses
2010-01-13T05:21:00.000
1
2,054,626
See the termios module, and the termios(3) man page.
0
543
true
0
1
How to disable shell interception of control characters?
2,054,648
2
5
0
5
10
1
1.2
0
Is it possible to distribute only the bytecode version (.pyc file) of a Python script instead of the original .py file? My app embeds the Python interpreter and calls PyImport_Import to load a script. How can I tell it to look for a .pyc file and import that?
0
python,c,compilation,bytecode
2010-01-13T08:30:00.000
0
2,055,355
I did it by creating .py library and simple .py program that uses that library. Then I compiled library to .pyc and distributed: program as .py source and library as compiled .pyc.
0
15,521
true
0
1
How to protect Python source code?
2,055,381
2
5
0
5
10
1
0.197375
0
Is it possible to distribute only the bytecode version (.pyc file) of a Python script instead of the original .py file? My app embeds the Python interpreter and calls PyImport_Import to load a script. How can I tell it to look for a .pyc file and import that?
0
python,c,compilation,bytecode
2010-01-13T08:30:00.000
0
2,055,355
Since you are writing your main program in C++, you can do whatever you want to protect your Python files. You could encrypt them for distribution, then decrypt them just in time to import them into the Python interpreter, for example. Since you are using PyImport_Import, you can write your own __import__ hook to import the modules not from a file but from a memory buffer, so your transformation to .pyc file can happen all in memory, with no understandable Python code on disk at all.
0
15,521
false
0
1
How to protect Python source code?
2,056,647
2
6
0
0
10
1
0
0
I'm new to Java, and I'd like to create some class variables that are dynamically calculated when accessed, as you can do in Python by using the property() method. However, I'm not really sure how to describe this, so Googling shows me lots about the Java "Property" class, but this doesn't appear to be the same thing. What is the Java equivalent of Python's property()?
0
java,python,properties
2010-01-13T13:03:00.000
0
2,056,752
Do you want to create new fields/getters/setters in the class? If you want to do this in runtime, you have to create completely new class with your fields and methods, and load it into the JVM. To create new class you can use library like ASM or CGLib, but if you're new to Java, this isn't something you want to start with.
0
3,624
false
1
1
What is the Java Equivalent of Python's property()?
2,056,762
2
6
0
2
10
1
0.066568
0
I'm new to Java, and I'd like to create some class variables that are dynamically calculated when accessed, as you can do in Python by using the property() method. However, I'm not really sure how to describe this, so Googling shows me lots about the Java "Property" class, but this doesn't appear to be the same thing. What is the Java equivalent of Python's property()?
0
java,python,properties
2010-01-13T13:03:00.000
0
2,056,752
They don't really exist. In Java it's common practice to declare members as private or protected and only allow access to them via methods. Often this leads to lots of small getFoo() and setFoo(newFoo) methods. Python doesn't really have private and protected and it's more common to allow direct access to members.
0
3,624
false
1
1
What is the Java Equivalent of Python's property()?
2,056,814