Hi there,
I'm trying to find information on different ways to traverse an object tree in python.
I don't know much about the language in general yet, so any suggestions/techniques would be welcome.
Thanks so much
jml
im trying to build android from source on ubuntu 10.04. when i enter the repo command:
repo init -u git://android.git.kernel.org/platform/manifest.git -b eclair
it get this error back
exec: 23: python: not found
any ideas.
I have two floats in Python that I'd like to subtract, i.e.
v1 = float(value1)
v2 = float(value2)
diff = v1 - v2
I want "diff" to be computed upto two significant figures, that is compute it using %.2f of v1 and %.2f of v2. How can I do this? I know how to print v1 and v2 up to two decimals, but not how to do arithmetic like that.
thanks.
Can we initialize python objects with statement like this:
a = b = c = None
it seems to me when I did a = b = c = list() will cause circular reference count issue.
Please give your expert advice.
I'm using the following code to hide stderr on Linux/OSX for a Python library I do not control that writes to stderr by default:
f = open("/dev/null","w")
zookeeper.set_log_stream(f)
Is there an easy cross platform alternative to /dev/null? Ideally it would not consume memory since this is a long running process.
Let's say that I have the following text:
in = "one aaa two bbbb three cccc"
I would like to parse this into a group of variables that contain
notworking = ["one", "two", "three"]
v1,v2,v3 = in.split(notworking)
I know that the example above won't work, but is there some utility in python that would allow me to use this sort of approach? I know what the identifiers will be in advance, so I would think that there has got to be a way to do this...
Thanks for any help,
jml
Hi
I have a list of points as shown below
points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
Some of the points have duplicate x,y values. What I want to do is to extract the unique maximum value x,y points
For example, if I have points [1,2,5] [1,1,3] [1,2,7] [1,7,3]
I would like to obtain the list [1,1,3] [1,2,7] [1,7,3]
How can I do this in python
Thanks
I am running a multithreaded application(Python2.7.3) in a Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz. I thought it would be using only one core but using the "top" command I see that the python processes are constantly changing the core no. Enabling "SHOW THREADS" in the top command shows diffrent thread processes working on different cores.
Can anyone please explain this? It is bothering me as I know from theory that multithreading is executed on a single core.
I have a string which is like this:
this is "a test"
I'm trying to write something in Python to split it up by space while ignoring spaces within quotes. The result I'm looking for is:
['this','is','a test']
PS. I know you are going to ask "what happens if there are quotes within the quotes, well, in my application, that will never happen.
It is recommended to not to use import * in python. Can anyone please share the reason for that, so that I can avoid it doing next time.
Thanks and Regards
Can somebody explain to me why this works (in Python 2.5) :
class Foo(object):
pass
class Bar(Foo):
pass
print(Foo.__subclasses__())
but this doesn't :
class Foo():
pass
class Bar(Foo):
pass
print(Foo.__subclasses__())
The latter returns "AttributeError: class Foo has no attribute '__subclasses__'" but i'm not sure why. I know this is related to old-style vs. new-style classes but i'm not clear on why that would make this functionality unavailable.
Hi! I was wondering how to make a simple Clipboard Monitor in python, for GUI I'm using PyGTK.
I found gtk.clipboard class and all that but I couldn't find any solution to get the "signals" to trigger the event when the clipboard content has changed :(
Any ideas?
Thanks you! :)
I have a system where a central Java controller launches analysis processes, which may be written in C++, Java, or Python (mostly they are C++). All these processes currently run on the same server. What are you suggestions to
Create a central log to which all processes can write to
What if in the future I push some processes to another server. How can I support distributed logging?
Thanks!
In the effort to learn python and/or ruby, I was wondering how a file shredder would be implemented? I would like it to take in a file as an argument and then employ an algorithm to make that file unrecoverable. Would possibly add the support for multiple files or even whole directories later.
How can I protect my web server, if I run custom users code on server. If any user can submit his python source on my server and run it.
Maybe some modules or linux tools for close any network and hardware activity for this script.
Thank's all for help!
Working with Python in Emacs if I want to add a try/catch to a block of code, I often find that I am having to indent the whole block, line by line. In Emacs, how do you indent the whole block at once.
I am not an experienced Emacs user, but just find it is the best tool for working through ssh. I am using Emacs on the command line(Ubuntu), not as a gui, if that makes any difference.
I want to parse a timestamp from a log file that has been written via
datetime.datetime.now().strftime('%Y%m%d%H%M%S')
and then compute the number of seconds that have passed since this timestamp.
I know I could do it with datetime.datetime.strptime to get back a datetime object and then compute a timedelta. Problem is, the strptime function has been introduced with Python 2.5 and I'm using Python2.4.4 (an upgrade is not possible in my context).
Any easy way to do this?
I know this question may well be the silliest question you've herd today, but to me it is a big question at this stage of my programming learning.
Why is the second empty line needed in this Python code? What does that line do?
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
Since input and raw_input() stop the program from running anymore, I want to use a subprocess to run this program...
while True: print raw_input()
and get its output.
This is what I have as my reading program:
import subprocess
process = subprocess.Popen('python subinput.py', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
output=process.stdout.read(12)
if output=='' and process.poll()!=None:
break
if output!='':
sys.stdout.write(output)
sys.stdout.flush()
When I run this, the subprocess exits almost as fast as it started. How can I fix this?
Hi,
I was wondering if there is a way to automatically run commands on entering the python shell as you would with the .bash_profile or .profile scripts with bash. I would like to automatically import some modules so I don't have to type the whole shebang everytime I hop into the shell.
Thanks,
Hello!
I`m trying to write simple batch file generator in python. Batch file consist of about 30-50 lines of text and is passed to other applications. During the execution of script there a lot of calls to external applications. I want to create file in memory (like named pipes in win32). Is there any platform independ way?
p.s. sorry for possible mistakes in text, I'm still learning English
given a list of python strings, how can I automatically convert them to their correct type? Meaning, if I have:
["hello", "3", "3.64", "-1"]
I'd like this to be converted to the list
["hello", 3, 3.64, -1]
where the first element is a stirng, the second an int, the third a float and the fourth an int.
how can I do this? thanks.
Much like Java (or php), I'm use to seperating the classes to files.
Is it the same deal in Python? plus, how should I name the file?
Lowercase like classname.py or the same like ClassName.py?
Do I need to do something special if I want to create an object from this class or does the fact that it's in the same "project" (netbeans) makes it ok to create an object from it?