I need to execute a script in the background through a service.
The service kicks off the script using Popen.
p = Popen('/path/to/script/script.py', shell=True)
Why doesn't the following script work when I include the file writes in the for loop?
#!/usr/bin/python
import os
import time
def run():
fd = open('/home/dilleyjrr/tes...
I need a function to determine if a directory is a mount point for a drive.
I found this code already which works well for linux:
def getmount(path):
path = os.path.abspath(path)
while path != os.path.sep:
if os.path.ismount(path):
return path
path = os.path.abspath(os.path.join(path, os.pardir))
return path
But I'...
So, I wanted to extend the Python smtpd SMTPServer class so that it could handle SMTP AUTH connections. Seemed simple enough...
So, it looked like I could just start like this:
def smtp_EHLO(self, arg):
print 'got in arg: ', arg
# do stuff here...
But for some reason, that never gets called. The Python smtpd library calls o...
I'm trying to use regular expression right now and I'm really confuse. I want to make some validation with this regular expression :
^[A-Za-z0-9_.][A-Za-z0-9_ ]*
I want to make it so there is a limit of character (32) and I want to "match" all the string.
ex:
string : ".hello hello"
-this should work
string : ".hello hello /.."
-T...
I am parsing some XML with the elementtree.parse() function. It works, except for some utf-8 characters(single byte character above 128). I see that the default parser is XMLTreeBuilder which is based on expat.
Is there an alternative parser that I can use that may be less strict and allow utf-8 characters?
This is the error I'm gett...
When trying to render a Django template file in Google App Engine
from google.appengine.ext.webapp import template
templatepath = os.path.join(os.path.dirname(file), 'template.html')
self.response.out.write (template.render( templatepath , template_values))
I come across the following error:
<type
'exceptions.UnicodeD...
Does anyone know the simplest way to import an OpenSSL RSA private/public key (using a passphrase) with a Python library and use it to decrypt a message.
I've taken a look at ezPyCrypto, but can't seem to get it to recognise an OpenSSL RSA key, I've tried importing a key with importKey as follows:
key.importKey(myKey, passphrase='PASS...
This is what I'm trying to do in Python:
class BaseClass:
def __init__(self):
print 'The base class constructor ran!'
self.__test = 42
class ChildClass(BaseClass):
def __init__(self):
print 'The child class constructor ran!'
BaseClass.__init__(self)
def doSomething(self):
print 'Test is: ', self.__test
test = ChildClass()
tes...
I can't run firefox from a sudoed python script that drops privileges to normal user. If i write
$ sudo python
>>> import os
>>> import pwd, grp
>>> uid = pwd.getpwnam('norby')[2]
>>> gid = grp.getgrnam('norby')[2]
>>> os.setegid(gid)
>>> os.seteuid(uid)
>>> import webbrowser
>>> webbrowser.get('firefox').open('www.google.it')
True
>>>...
In other languages I can obtain the current frame via a reflection api to determine what variables are local to the scope that I an currently in.
Is there a way to do this in Python?
...
I have some data in CSV format that I want to pull into an Excel spreadsheet and then create some standard set of graphs for. Since the data is originally generated in a Python app, I was hoping to simply extend the app so that it could do all the post processing and I wouldn't have to do it by hand. Is there an easy interface with Pytho...
I'm looking for a quick way to get an http response code from a url (i.e. 200, 404, etc). Not sure which library to use.
Thanks
...
Lately, I tried to set local variables from outside of a running generator. The generator code also should access these variables.
One trouble was, that when accessing the variables, it seamed that the interpreter was thinking it must be a global since the variable was not set in the local scope. But I don't wanted to change the global ...
Hi,
I am trying to parse XML with Python but not getting very far. I think it's due to wrong XML tree this API returns.
So this is what is returned by the GET request:
<codigo>3</codigo><valor></valor><operador>Dummy</operador>
The GET request goes here:
http://69.36.9.147:8090/clientes/SMS_API_OUT.jsp?codigo=ABCDEFGH&cliente=XX...
I wrote:
Object result = (Object)client.execute("method",params);
in java client.
Actually, the result should be printed in string format. But I can only output the address of "Object result", how can I get the content?
And I have tried String result = (String)client.execute("method",params);
It says lang.until.Object can not cast ...
I realize this is a broad topic, but I'm looking for a good primer on parsing meaning from text, ideally in Python. As an example of what I'm looking to do, if a user makes a blog post like:
"Manny Ramirez makes his return for the Dodgers today against the Houston Astros",
what's a light-weight/ easy way of getting the nouns out of a s...
I have some code in a python string that contains extraneous empty lines. I would like to remove all empty lines from the string. What's the most pythonic way to do this?
Note: I'm not looking for a general code re-formatter, just a quick one or two-liner.
Thanks!
...
I'm trying to implement dynamic reloading objects in Python, that reflect code changes live.
Modules reloading is working, but I have to recreate every instance of the modules' classes for changes to become effective.
The problem is that objects data (objects __dict__ content) is lost during the process.
So I tried another approach:
...
Python 3.x renamed the low-level module 'thread' to '_thread' -- I don't see why in the documentation. Does anyone know?
...
Dear Sir/Madam.
My name is Duc from University of Technology. I have faced a difficult problem. That is reading data file:
///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2...