Re: import newer

2011-03-20 Thread eryksun ()
On Sunday, March 20, 2011 12:27:38 AM UTC-4, xinyou yan wrote:
> I begin to study with  <>
> 
> I met a problem with import.
> 
> first
> I creat a  file  hello.py
> 
> then in fedora /14
> I type python to  the interpreter
> 
> >>> import hello
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named hello
> 
> What should i do now.
> The  current path is not  added  defaultly ?

>>> import os
>>> os.listdir(os.getcwd())

Is hello.py in the returned list?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk/list

2011-03-20 Thread Peter Otten
ecu_jon wrote:

> so i am trying to add md5 checksum calc to my file copy stuff, to make
> sure the source and dest. are same file.
> i implemented it fine with the single file copy part. something like :
> for files in sourcepath:
> f1=file(files ,'rb')
> try:
> shutil.copy2(files,
> os.path.join(destpath,os.path.basename(files)))
> except:
> print "error file"
> f2=file(os.path.join(destpath,os.path.basename(files)), 'rb')
> truth = md5.new(f1.read()).digest() ==
> md5.new(f2.read()).digest()
> if truth == 0:
> print "file copy error"
> 
> this worked swimmingly. i moved on to my backupall function, something
> like
> for (path, dirs, files) in os.walk(source):
> #os.walk drills down thru all the folders of source
> for fname in dirs:
>currentdir = destination+leftover
> try:
>os.mkdir(os.path.join(currentdir,fname),0755)
> except:
> print "error folder"
> for fname in files:
> leftover = path.replace(source, '')
> currentdir = destination+leftover
> f1=file(files ,'rb')
> try:
> shutil.copy2(os.path.join(path,fname),
>  os.path.join(currentdir,fname))
> f2 = file(os.path.join(currentdir,fname,files))
> except:
> print "error file"
> truth = md5.new(f1.read()).digest() ==
> md5.new(f2.read()).digest()
> if truth == 0:
> print "file copy error"
> 
> but here, "fname" is a list, not a single file.i didn't really want to
> spend a lot of time on the md5 part. thought it would be an easy add-
> on. i don't really want to write the file names out to a list and
> parse through them one a time doing the calc, but it sounds like i
> will have to do something like that.

If you have something working for one file, don't copy the code into the 
os.walk() for-loop, put it into a function, say:

def safe_copy(sourcefile, destfolder):
# your code

Then call that thoroughly tested function from within the os.walk() loop

for path, folders, files in os.walk(sourceroot):
destfolder = ... # os.path.relpath() might help here
# ... (make subdirectories)
for name in files:
sourcefile = os.path.join(path, name)
safe_copy(sourcefile, destfolder)

If you find a bug in safe_copy() you'll only have to fix it in one place.
Also, you can test it with a single file which should be easier and faster 
than processing a whole directory tree.

Generally speaking breaking code into small functions that can be tested 
individually is a powerful technique. And you don't have to stop here, you 
can break safe_copy() into

def safe_copy(sourcefile, destfolder):
destfile = ...
copyfile(sourcefile, destfile)
if not equal_content(sourcefile, destfile):
# print a warning or raise an exception

Sometimes you'll even find that the smaller more specialized routines 
already exist in the standard library.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: send function keys to a legacy DOS program

2011-03-20 Thread LehH Sdsk8
On Mar 10, 9:58 pm, Justin Ezequiel 
wrote:
> Greetings,
>
> We have an old barcode program (MSDOS and source code unavailable.)
> I've figured out how to populate the fields (by hacking into one of
> the program's resource files.)
> However, we still need to hit the following function keys in sequence.
> F5, F2, F7
> Is there a way to pipe said keys into the program?
>
> I know it's not really a python problem but I got nowhere else to go.
> I've tried other barcode solutions but none give the same output.

You should try these links:
http://www.rhinocerus.net/forum/lang-asm-x86/254441-re-how-write-char-keyboard-buffer.html
http://bytes.com/topic/c/answers/212952-keyboard-buffer
http://bytes.com/topic/c/answers/747883-writing-into-keyboard-buffer-aix
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bounds checking

2011-03-20 Thread Martin De Kauwe
On Mar 19, 8:40 pm, Steven D'Aprano  wrote:
> On Sat, 19 Mar 2011 01:38:10 -0700, Martin De Kauwe wrote:
> >> Why don't you do the range check *before* storing it in state? That way
> >> you can identify the calculation that was wrong, instead of merely
> >> noticing that at some point some unknown calculation went wrong.
>
> > I guess no reason really. I suppose in my mind I was thinking it was an
> > unlikely safeguard but I liked the idea of adding so would just do it at
> > the end of a time step. In reality I think there is practically no
> > difference and this way it is done once, in a single location vs.
> > potential 10 separate checks? I don't see the advantage?
>
> You should always aim to fail as close as possible to the source of the
> error as is practical. That decreases the amount of debugging required
> when something fails: instead of searching your entire program, you only
> have to search a very small amount of code.
>
> --
> Steven

OK I take your point and can see the superior logic! I shall amend
what I was planning
-- 
http://mail.python.org/mailman/listinfo/python-list


value of pi and 22/7

2011-03-20 Thread Gerald Britton
Surely on track for the *slowest* way to compute pi in Python (or any
language for that matter):

math.sqrt( sum( pow(k,-2) for k in xrange(sys.maxint,0,-1)  ) * 6.  )

Based on the Riemann zeta function:

   The sum of

1/k^2 for k = 1:infinity

   converges to pi^2 / 6

Depending on your horsepower and the size of sys.maxint on your
machine, this may take a few *days* to run.

Note: The sum in the Python expression above runs in reverse to
minimize rounding errors.

-- 
Gerald Britton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some Minor questions on Class and Functions

2011-03-20 Thread joy99
On Mar 20, 11:13 am, joy99  wrote:
> On Mar 20, 9:39 am, Steven D'Aprano 
>
>
> [email protected]> wrote:
> > On Sat, 19 Mar 2011 16:57:58 -0700, joy99 wrote:
> > > Dear Group,
>
> > > I am trying to pose two small questions.
>
> > > 1) I am using Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.
> > > 1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()"
> > > for more information, on WINXP SP2.
>
> > > As I am writing a code for class like the following: IDLE 2.6.5
> >  class Message:
> > >    def __init__(self,str1):
> > >            self.text="MY NAME"
> > >    def printmessage(self):
> > >            print self.text
>
> > > It works fine as can be seen in the result:
> >  x1=Message(1)
> >  x1.printmessage()
> > > MY NAME
>
> > > Now if I open a new window and write the same code value in printmessage
> > > is giving arbitrary or no values.
>
> > The description of your problem does not make sense to me. Can you show
> > an example?
>
> > > 2) Suppose I have a code:
>
> >  def hello():
> > >    print "HELLO SIR"
>
> > > Can I write another function where I can call the value of this function
> > > or manipulate it?
>
> > No. The string "HELLO SIR" is a local variable to the hello() function.
> > You cannot modify it from outside that function. Since your hello()
> > function prints the result, instead of returning it, another function
> > cannot capture it either.
>
> > Perhaps what you want is something like this:
>
> > def hello(message="HELLO SIR"):
> >     return message
>
> > Now you can call the function, and print the result:
>
> > print hello()
>
> > If you want to capture the return value, you can:
>
> > result = hello()
> > print result.lower()
>
> > If you want to change the message used, you can pass it to the function
> > as an argument:
>
> > hello("Greetings and salutations!")
>
> > Hope this helps,
>
> > --
> > Steven
>
> Thanks Steven and Benjamin for your kind time to answer my question. I
> am sending the code soon, actual code is pretty long that has so many
> variables, it may well take your long time to evaluate, so I am making
> a sizable prototype and trying to send it to you.
> Best Regards,
> Subhabrata.

Sir,

I am writing the code as below. I am trying to send also the error
messages and my doubts.

class Message:
def __init__(self,string1,string2,lenstr1,lenstr2):
self.string1="MY"
self.string2="NAME"
self.lenstr1=lenstr1
self.lenstr2=lenstr2
def lenstring(self):
lenstr1=len(self.string1)
lenstr2=len(self.string2)
def printstr(self):
print lenstr1
print lenstr2

IDLE 2.6.5
>>>  RESTART 
>>>
>>> x1=Message(1,2,3,4)
>>> x1.printstr()

Traceback (most recent call last):
  File "", line 1, in 
x1.printstr()
  File "D:/Python26/Message3.py", line 11, in printstr
print lenstr1
NameError: global name 'lenstr1' is not defined

My doubts are:
i) Am I doing something wrong? In calling the values/parameters?
ii)As I am calling the class with so many parameters, I must be doing
something very wrong. What is the solution if you can kindly suggest.
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some Minor questions on Class and Functions

2011-03-20 Thread Noah Hall
> class Message:
>    def __init__(self,string1,string2,lenstr1,lenstr2):
>        self.string1="MY"
>        self.string2="NAME"
>        self.lenstr1=lenstr1
>        self.lenstr2=lenstr2

The variables string1 and string2 that you're passing here are in fact
useless. They don't do anything inside the method. Is there any point
for them? There's no need to pass __init__ variables just so you can
assign self.variable_name = "fixed text".

>    def lenstring(self):
>        lenstr1=len(self.string1)
>        lenstr2=len(self.string2)

I think you want self.lenstr1 and self.lenstr2 here - otherwise you're
assigning local variables with the same name as those defined within
the class, and throwing them away.

>    def printstr(self):
>        print lenstr1
>        print lenstr2

Again, I think you want self.lenstr1 and self.lenstr2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some Minor questions on Class and Functions

2011-03-20 Thread joy99
On Mar 20, 6:18 pm, Noah Hall  wrote:
> > class Message:
> >    def __init__(self,string1,string2,lenstr1,lenstr2):
> >        self.string1="MY"
> >        self.string2="NAME"
> >        self.lenstr1=lenstr1
> >        self.lenstr2=lenstr2
>
> The variables string1 and string2 that you're passing here are in fact
> useless. They don't do anything inside the method. Is there any point
> for them? There's no need to pass __init__ variables just so you can
> assign self.variable_name = "fixed text".
>
> >    def lenstring(self):
> >        lenstr1=len(self.string1)
> >        lenstr2=len(self.string2)
>
> I think you want self.lenstr1 and self.lenstr2 here - otherwise you're
> assigning local variables with the same name as those defined within
> the class, and throwing them away.
>
> >    def printstr(self):
> >        print lenstr1
> >        print lenstr2
>
> Again, I think you want self.lenstr1 and self.lenstr2

Sir,
Thanks for your kind time and suggestion. I'll repair.
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some Minor questions on Class and Functions

2011-03-20 Thread joy99
On Mar 20, 6:18 pm, Noah Hall  wrote:
> > class Message:
> >    def __init__(self,string1,string2,lenstr1,lenstr2):
> >        self.string1="MY"
> >        self.string2="NAME"
> >        self.lenstr1=lenstr1
> >        self.lenstr2=lenstr2
>
> The variables string1 and string2 that you're passing here are in fact
> useless. They don't do anything inside the method. Is there any point
> for them? There's no need to pass __init__ variables just so you can
> assign self.variable_name = "fixed text".
>
> >    def lenstring(self):
> >        lenstr1=len(self.string1)
> >        lenstr2=len(self.string2)
>
> I think you want self.lenstr1 and self.lenstr2 here - otherwise you're
> assigning local variables with the same name as those defined within
> the class, and throwing them away.
>
> >    def printstr(self):
> >        print lenstr1
> >        print lenstr2
>
> Again, I think you want self.lenstr1 and self.lenstr2

Sir,
It worked. Just Thanks.
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


gdbm thread safety

2011-03-20 Thread Laszlo Nagy

 Hi,

Are gdbm objects thread safe? I searched through mailing list archives 
and the documentation but did not find the answer.


My only concerns are:

   * is it safe to use the same gdbm object in read-only mode from many
 threads?
   * is it safe to use the same gdbm object from many threads, where
 there is only one writer and many readers:

Thanks,

   Laszlo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk/list

2011-03-20 Thread ecu_jon
yes i agree breaking stuff into smaller chunks is a good way to do it.
even were i to do something like

def safe_copy()
f1=file(files ,'rb')
f2 = file(os.path.join(currentdir,fname,files))
truth = md5.new(f1.read()).digest() ==
md5.new(f2.read()).digest()
if truth == 0:
print "file copy error"

that would probably work for the single file copy functions. but would
still breakdown during the for ...os.walk(), again because "fname" is
a list there, and the crypto functions work 1 file at a time. even
changing crypto functions wouldn't change that.
-- 
http://mail.python.org/mailman/listinfo/python-list


drawing polygons in Google Earth using wxpython

2011-03-20 Thread !!AhmedLegend!!
...i am working on my graduation project and i need to draw some
polygons in Google Earth map automatically using python so any one was
subjected to something like that or have a solution plz respond
ASAP ...given that i was able to open Google Earth from python and
focus on a certain point and also i have no previous background with
using kmlthanks in  advance
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: psutil (python process utilities) 0.2.1 released

2011-03-20 Thread Giampaolo Rodolà
Hi,
I'm pleased to announce the 0.2.1 release of psutil:
http://code.google.com/p/psutil

=== About ===

psutil is a module providing an interface for retrieving information
on running processes and system utilization (CPU, memory) in a
portable way by using Python, implementing many functionalities
offered by command line tools like ps, top, kill, lsof and netstat.

It currently supports Linux, Windows, OS X and FreeBSD both 32-bit and
64-bit with Python versions from 2.4 to 3.2 by using a unique code
base.


=== Major enhancements ===

* per-process I/O counters
* per-process wait() (wait for process to terminate and return its exit code)
* per-process get_threads() returning information (id, user and kernel
times) about threads opened by process.
* per-process real, effective and saved user and group ids.
* per-process get and set niceness (priority)
* per-process status
* per-process I/O nice (priority) - Linux only
* psutil.Popen class which tidies up subprocess.Popen and
psutil.Process in a unique interface.
* system boot time

=== New features by example ===

>>> p = psutil.Process(7055)
>>> p.name
'python'
>>>
>>> p.status
0
>>> str(p.status)
'running'
>>>
>>> p.uids
user(real=1000, effective=1000, saved=1000)
>>> p.gids
group(real=1000, effective=1000, saved=1000)
>>>
>>> p.nice
0
>>> p.nice = 10  # set/change process priority
>>> p.nice
10
>>>
>>> p.get_ionice()
ionice(ioclass=0, value=0)
>>> p.set_ionice(psutil.IOPRIO_CLASS_IDLE)  # change process I/O priority
>>> p.get_ionice()
ionice(ioclass=3, value=0)
>>>
>>> p.get_io_counters()
io(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632)
>>>
>>> p.get_threads()
[thread(id=5234, user_time=22.5, system_time=9.2891),
 thread(id=5235, user_time=0.0, system_time=0.0),
 thread(id=5236, user_time=0.0, system_time=0.0),
 thread(id=5237, user_time=0.0707, system_time=1.2)]
>>>
>>> p.terminate()
>>> p.wait(timeout=3)
0
>>>


= new subprocess interface =

>>> import psutil
>>> from subprocess import PIPE
>>> p = psutil.Popen(["/usr/bin/python", "-c", "print 'hi'"], stdout=PIPE)
>>> p.name
'python'
>>> p.uids
user(real=1000, effective=1000, saved=1000)
>>> p.username
'giampaolo'
>>> p.communicate()
('hi\n', None)
>>> p.terminate()
>>> p.wait(timeout=2)
0
>>>


=== Links ===

* Home page: http://code.google.com/p/psutil
* Mailing list: http://groups.google.com/group/psutil/topics
* Source tarball: http://psutil.googlecode.com/files/psutil-0.2.1.tar.gz
* Api Reference: http://code.google.com/p/psutil/wiki/Documentation



--- Giampaolo Rodola'

http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Could I joined in this Happy family

2011-03-20 Thread Colin J. Williams
On 18-Mar-11 15:47 PM, Nick Stinemates wrote:
> Welcome aboard !
> 
> On Mar 18, 2011 11:34 AM, "duxiu xiang"  > wrote:
>  > Dear friends:
>  > I am in China.For some rearon,I cannot visit your Google Group.May
>  > I joint this mail list for help in learning Python?
>  >
>  > --
>  > 笑看嫣红染半山,逐风万里白云间。
> 
You might try: http://gmane.org/

Colin W.

-- 
http://mail.python.org/mailman/listinfo/python-list


os.utime

2011-03-20 Thread monkeys paw

I used os.uname to succesfully change the access and mod times of
a file. My question is, is there any other date store for a file that
indicates the creation time, or is it impossible to detect that a file
with an older mod/access time is actually a 'new' file?

os.utime('sum.py', (time.time(),time.time())
--
http://mail.python.org/mailman/listinfo/python-list


Re: ttk styles

2011-03-20 Thread Peter
Here is what I came up with - hopefully I have understood the process
correctly and therefore that the comments are correct :-)

I am not sure I have the color of the indicator when it is (de)pressed
correct, but to my eyes the color 'snow' looks like the same color
used with a Tkinter Checkbutton with indicatoron=false.

r = Tk()

s = Style()

# create a layout that excludes the indicator element
s.layout('NoIndicator.TCheckbutton',
 [('Checkbutton.border',
   {'children': [('Checkbutton.padding',
  {'children': [('Checkbutton.label',
{})]})]})])

# Now create(?) a 'setting' for the border appearance of the
checkbutton
s.theme_settings('default', {
'NoIndicator.TCheckbutton': {'configure': {'relief': ''}}})

# set the attributes of the 'setting' to provide the required
behaviour
s.map('NoIndicator.TCheckbutton',
  relief=[('disabled', 'flat'),
  ('selected', 'sunken'),
  ('pressed', 'sunken'),
  ('active', 'raised'),
  ('!active', 'raised')],
  background=[('selected', 'snow')])

button = Checkbutton(r,
 text='Test',
 style='NoIndicator.TCheckbutton')
button.pack()

r.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.utime

2011-03-20 Thread Dan Stromberg
1) If you want to set the ctime to the current time, you can os.rename() the
file to some temporary name, and then quickly os.rename() it back.

2) You can sort of set a file to have an arbitrary ctime, by setting the
system's clock to what you need, and then doing the rename thing above -
then restore the clock back to what it should be.

3) You can also use some sort of tool that knows the details of how inodes
are stored on disk.  You'll likely need to do this with the filesystem
unmounted at the time, though if the inode isn't currently cached in RAM,
you might be able to get away without the umount and mount.

#2 and #3 require root access typically.

If a teacher is looking for assignments on a timesharing system to have been
turned in by a certain time, the ctime is the best time field to check.

On Sun, Mar 20, 2011 at 4:52 PM, monkeys paw  wrote:

> I used os.uname to succesfully change the access and mod times of
> a file. My question is, is there any other date store for a file that
> indicates the creation time, or is it impossible to detect that a file
> with an older mod/access time is actually a 'new' file?
>
> os.utime('sum.py', (time.time(),time.time())
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.utime

2011-03-20 Thread Christian Heimes
Am 21.03.2011 00:52, schrieb monkeys paw:
> I used os.uname to succesfully change the access and mod times of
> a file. My question is, is there any other date store for a file that
> indicates the creation time, or is it impossible to detect that a file
> with an older mod/access time is actually a 'new' file?
> 
> os.utime('sum.py', (time.time(),time.time())

In general POSIX OS don't have the means to store and return the
creation time of a file. Although os.stat() returns a struct that
contains st_ctime, it's NOT the creation time stamp. Often people
confuse the 'c' in st_ctime for creation time. It's the last status
change, e.g. change of ownership. Some file system may store the
creation time stamp but I know of no cross platform way to query the
information. Windows and NTFS are a whole different beast. AFAIR NTFS
has a creation time stamp.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Pyserial

2011-03-20 Thread Manatee
The windows msi install fails saying there is no python install found
in the registry. Is there a workaround for this? Can I edit the
registry and manually enter the information?

I am running Python 2.71

There is no traceback, the installation fails immediately

-- 
http://mail.python.org/mailman/listinfo/python-list


Regex in if statement.

2011-03-20 Thread Ken D'Ambrosio
Hey, all -- I know how to match and return stuff from a regex, but I'd
like to do an if, something like (from Perl, sorry):

if (/MatchTextHere/){DoSomething();}

How do I accomplish this in Python?

Thanks!

-Ken




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial

2011-03-20 Thread Terry Reedy

On 3/20/2011 8:46 PM, Manatee wrote:

The windows msi install fails saying there is no python install found
in the registry. Is there a workaround for this? Can I edit the
registry and manually enter the information?

I am running Python 2.71

There is no traceback, the installation fails immediately


Assuming your 2.7.1 was installed normally, with the CPython .msi 
installer from python.org, you should perhaps ask the pyserial folks.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial

2011-03-20 Thread Littlefield, Tyler

>The windows msi install fails saying there is no python install found
>in the registry. Is there a workaround for this? Can I edit the
>registry and manually enter the information?
I've came to realize that the 64-bit version of python does not work 
with 32-bit modules in terms of the installer because the key doesn't 
exist. Just grab the 32-bit python and you're set with modules.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Regex in if statement.

2011-03-20 Thread Benjamin Kaplan
On Sun, Mar 20, 2011 at 8:46 PM, Ken D'Ambrosio  wrote:
> Hey, all -- I know how to match and return stuff from a regex, but I'd
> like to do an if, something like (from Perl, sorry):
>
> if (/MatchTextHere/){DoSomething();}
>
> How do I accomplish this in Python?
>
> Thanks!
>
> -Ken
>

Python doesn't have regular expressions as a language feature. It's
just a module in the standard library.

import re
if re.search(pattern, string) :
   Stuff


However, regular expressions aren't used as much in Python as they are
in Perl. Regular expressions are overkill for a lot of applications.
If you're just checking to see if a string contains some text, use "if
substring in string". If you're checking to see if some text is at the
start of the string, do string.startswith(substring).

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regex in if statement.

2011-03-20 Thread Terry Reedy

On 3/20/2011 8:46 PM, Ken D'Ambrosio wrote:

Hey, all -- I know how to match and return stuff from a regex, but I'd
like to do an if, something like (from Perl, sorry):

if (/MatchTextHere/){DoSomething();}

How do I accomplish this in Python?


Look at the doc to see what are the possible return values from the 
function you want to use and which indicates failure. Then test that the 
result is not the failure value.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


python time

2011-03-20 Thread ecu_jon
I'm working on a script that will run all the time. at time specified
in a config file, will kick-off a backup.
problem is, its not actually starting the job. the double while loop
runs, the first comparing date works. the second for hour/min does
not.

#python file
import os,string,,time,getpass,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime

config = ConfigParser.ConfigParser()
config.read("config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
date = config.get("myvars", "date")
time = config.get("myvars", "time")
str_time=strftime("%H:%M",localtime())

while datetime.now().weekday() == int(date):
while str_time == time:
print "do it"

#config file
#change the time variable to "now"+a min or two to observe
#this needs to be where ever the actual python script is
[myvars]
#only set source if you want it to be different
source: c:\users\jon
destination: \\mothera\jon\
#what day of the week to perform backup?where Monday is 0 and Sunday
is 6
date: 6
#time to start
time: 21:02
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regex in if statement.

2011-03-20 Thread python
I agree with previous comments.
There are plenty of good tutorials, I have
sometimes found more useful for learning than the manuals.
The manuals are good but I prefer examples.

http://www.tutorialspoint.com/python/python_reg_expressions.htm

http://www.awaretek.com/tutorials.html#regular

Bill Sneddon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regex in if statement.

2011-03-20 Thread Rhodri James

On Mon, 21 Mar 2011 00:46:22 -, Ken D'Ambrosio  wrote:


Hey, all -- I know how to match and return stuff from a regex, but I'd
like to do an if, something like (from Perl, sorry):

if (/MatchTextHere/){DoSomething();}

How do I accomplish this in Python?


The basic routine is to do the match and test the returned object:

match_obj = re.match(pattern, string)
if match_obj is not None:
  do_something(match_obj)

If you don't need the match object (you aren't doing group capture,
say), obviously you can fold the first two of those lines together.

This can be a bit of a pain if you have a chain of tests to do
because of having to stop to save the match object.  To get around
that, wrap the match in something that stashes the match object.
Here's a primitive class-based version:

import re

class Match(object):
  def __init__(self):
self.match_obj = None

  def match(self, *args, **kwds):
self.match_obj = re.match(*args, **kwds)
return self.match_obj is not None

match = Match()
if match.match(pattern1, string1):
  do_something(match.match_obj)
elif match.match(pattern2, string2):
  do_something_else(match.match_obj)

Knowing more about what it is you want to do, you should be able
to do better than that.  As other people have said though,
regular expressions are often overkill, and it's worth thinking
about whether they really are the right answer to your problem.
Coming from Perl, it's easy to get into the mindset of applying
regexes to everything regardless of how appropriate they are.  I
certainly did!

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regex in if statement.

2011-03-20 Thread Thomas L. Shinnick

At 07:46 PM 3/20/2011, Ken D'Ambrosio wrote:

Hey, all -- I know how to match and return stuff from a regex, but I'd
like to do an if, something like (from Perl, sorry):

if (/MatchTextHere/){DoSomething();}

How do I accomplish this in Python?


You say you've done matching and accessing stuff from the regex match 
result, something like this longhand:

mo = text_password_guard_re.match( text )
if mo:
text = mo.group(1) + " **"
The above captured the match object result value and then checked 
that result.  If no match then the result value would be None and the 
if would not execute.


The above used a pre-compiled regex and called .match() on that.  You 
can instead use a pattern string directly.

mo = re.match(r"foo(\d+)", text)
if mo:
text = mo.group(1) + " **"

And if you don't need any captures (as you say) then you can just use 
the call in the if directly:

if re.match(r"foo\d+", text):
print("foo multiplied!")

And the above examples used .match(), to match starting from the 
beginning of the text string, but you can also use .search()

if re.search(r"foo", text):
print("foo found somewhere in text!")

To my mind Python wants to require all usages/contexts be explicit, 
requiring elaborations on your intent, whereas Perl was rather more 
happy to try to understand your intentions with what little you gave 
it.  Enter much disputation here.


Anyway, read all you can, especially any Python code you can lay your 
hands on, get the mindset from that, and just code.



Thanks!

-Ken


--
http://mail.python.org/mailman/listinfo/python-list


Re: send function keys to a legacy DOS program

2011-03-20 Thread Justin Ezequiel
On Mar 20, 7:30 am, Alexander Gattin  wrote:
> On Sun, Mar 20, 2011 at 12:52:28AM +0200,
>
> You need to place 2 bytes into the circular buffer
> to simulate key press. Lower byte is ASCII code,
> higher byte is scan code (they are the same for
> functional keys, whe using default keycode set#1):
>
> F5: 0x3F 0x3F
> F2: 0x3C 0x3C
> F7: 0x41 0x41
>
> --
> With best regards,
> xrgtn

looks promising. will give this a try. thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread Dave Angel

On 01/-10/-28163 02:59 PM, ecu_jon wrote:

I'm working on a script that will run all the time. at time specified
in a config file, will kick-off a backup.
problem is, its not actually starting the job. the double while loop
runs, the first comparing date works. the second for hour/min does
not.

#python file
import os,string,,time,getpass,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime

config = ConfigParser.ConfigParser()
config.read("config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
date = config.get("myvars", "date")
time = config.get("myvars", "time")
str_time=strftime("%H:%M",localtime())

while datetime.now().weekday() == int(date):
 while str_time == time:
 print "do it"




You're comparing two objects in that inner while-loop, but since they 
never change, they'll never match unless they happen to start out as 
matched.


you need to re-evaluate str_time each time through the loop.  Make a 
copy of that statement and put it inside the loop.


You probably don't want those loops to be comparing to ==, though, since 
if you start this script on some other day, it'll never loop at all. 
Also, it'd be good to do some form of sleep() function when you're 
waiting, so you don't bog the system down with a busy-loop.


DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial

2011-03-20 Thread Manatee
On Mar 20, 9:06 pm, "Littlefield, Tyler"  wrote:
>  >The windows msi install fails saying there is no python install found
>  >in the registry. Is there a workaround for this? Can I edit the
>  >registry and manually enter the information?
> I've came to realize that the 64-bit version of python does not work
> with 32-bit modules in terms of the installer because the key doesn't
> exist. Just grab the 32-bit python and you're set with modules.

Ok, great. Let me try that. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.utime

2011-03-20 Thread Christian Heimes
Am 21.03.2011 01:40, schrieb Dan Stromberg:
> 1) If you want to set the ctime to the current time, you can os.rename() the
> file to some temporary name, and then quickly os.rename() it back.
> 
> 2) You can sort of set a file to have an arbitrary ctime, by setting the
> system's clock to what you need, and then doing the rename thing above -
> then restore the clock back to what it should be.
> 
> 3) You can also use some sort of tool that knows the details of how inodes
> are stored on disk.  You'll likely need to do this with the filesystem
> unmounted at the time, though if the inode isn't currently cached in RAM,
> you might be able to get away without the umount and mount.
> 
> #2 and #3 require root access typically.

You don't have to renmae the file to set the ctime to current time
stamp. os.chmod(), os.chown(), os.link() and possible other function set
the ctime of a file. However ctime is *not* the creation time stamp on
POSIX OSes.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial

2011-03-20 Thread Manatee
On Mar 20, 9:06 pm, "Littlefield, Tyler"  wrote:
>  >The windows msi install fails saying there is no python install found
>  >in the registry. Is there a workaround for this? Can I edit the
>  >registry and manually enter the information?
> I've came to realize that the 64-bit version of python does not work
> with 32-bit modules in terms of the installer because the key doesn't
> exist. Just grab the 32-bit python and you're set with modules.

I installed python 2.71 32bit and reset the path environment variable;
re-ran pyserial msi file and all is good in OZ. Thank you very much. I
may just get this Python after all. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.utime

2011-03-20 Thread Dan Stromberg
On Sun, Mar 20, 2011 at 7:12 PM, Christian Heimes  wrote:

> Am 21.03.2011 01:40, schrieb Dan Stromberg:
> > 1) If you want to set the ctime to the current time, you can os.rename()
> the
> > file to some temporary name, and then quickly os.rename() it back.
> >
> > 2) You can sort of set a file to have an arbitrary ctime, by setting the
> > system's clock to what you need, and then doing the rename thing above -
> > then restore the clock back to what it should be.
> >
> > 3) You can also use some sort of tool that knows the details of how
> inodes
> > are stored on disk.  You'll likely need to do this with the filesystem
> > unmounted at the time, though if the inode isn't currently cached in RAM,
> > you might be able to get away without the umount and mount.
> >
> > #2 and #3 require root access typically.
>
> You don't have to renmae the file to set the ctime to current time
> stamp. os.chmod(), os.chown(), os.link() and possible other function set
> the ctime of a file.


Yes, I probably should've used a quantifier on my single example.


> However ctime is *not* the creation time stamp on
> POSIX OSes.
>

Well, it is, and it's not.  It was originally called "creation time", but
many today find "change time" a better description of what it actually does,
sort of retroactively changing what the "c" means.  This is because the
ctime reflects the change time of an inode, not of the file's content - but
most people don't really care what an inode is.  Sometimes that's the same
as the time at which the file was created, but it doesn't necessarily remain
so throughout the file's lifetime.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread ecu_jon
On Mar 20, 10:09 pm, Dave Angel  wrote:
> On 01/-10/-28163 02:59 PM, ecu_jon wrote:
>
>
>
> > I'm working on a script that will run all the time. at time specified
> > in a config file, will kick-off a backup.
> > problem is, its not actually starting the job. the double while loop
> > runs, the first comparing date works. the second for hour/min does
> > not.
>
> > #python file
> > import os,string,,time,getpass,ConfigParser
> > from datetime import *
> > from os.path import join, getsize
> > from time import strftime,localtime
>
> > config = ConfigParser.ConfigParser()
> > config.read("config.ini")
> > source = config.get("myvars", "source")
> > destination = config.get("myvars", "destination")
> > date = config.get("myvars", "date")
> > time = config.get("myvars", "time")
> > str_time=strftime("%H:%M",localtime())
>
> > while datetime.now().weekday() == int(date):
> >      while str_time == time:
> >          print "do it"
>
> You're comparing two objects in that inner while-loop, but since they
> never change, they'll never match unless they happen to start out as
> matched.
>
> you need to re-evaluate str_time each time through the loop.  Make a
> copy of that statement and put it inside the loop.
>
> You probably don't want those loops to be comparing to ==, though, since
> if you start this script on some other day, it'll never loop at all.
> Also, it'd be good to do some form of sleep() function when you're
> waiting, so you don't bog the system down with a busy-loop.
>
> DaveA

i guess im just having a hard time creating something like
check if go condition,
else sleep

the double while loops take 12% cpu usage on my machine so this is
probably unacceptable.
also the sleep command does not like me :
 >>> from datetime import *
>>> from time import strftime,localtime,sleep
>>> time.sleep(3)

Traceback (most recent call last):
  File "", line 1, in 
time.sleep(3)
AttributeError: type object 'datetime.time' has no attribute 'sleep'
>>>

here it is updated with the hour/min check fixed.
#updated python code
import os,string,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime,sleep

config = ConfigParser.ConfigParser()
config.read("config.ini")
date = config.get("myvars", "date")
time = config.get("myvars", "time")

while datetime.now().weekday() == int(date):
str_time=strftime("%H:%M",localtime())
while str_time == time:
print "do it"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread ecu_jon
On Mar 20, 10:48 pm, ecu_jon  wrote:
> On Mar 20, 10:09 pm, Dave Angel  wrote:
>
>
>
> > On 01/-10/-28163 02:59 PM, ecu_jon wrote:
>
> > > I'm working on a script that will run all the time. at time specified
> > > in a config file, will kick-off a backup.
> > > problem is, its not actually starting the job. the double while loop
> > > runs, the first comparing date works. the second for hour/min does
> > > not.
>
> > > #python file
> > > import os,string,,time,getpass,ConfigParser
> > > from datetime import *
> > > from os.path import join, getsize
> > > from time import strftime,localtime
>
> > > config = ConfigParser.ConfigParser()
> > > config.read("config.ini")
> > > source = config.get("myvars", "source")
> > > destination = config.get("myvars", "destination")
> > > date = config.get("myvars", "date")
> > > time = config.get("myvars", "time")
> > > str_time=strftime("%H:%M",localtime())
>
> > > while datetime.now().weekday() == int(date):
> > >      while str_time == time:
> > >          print "do it"
>
> > You're comparing two objects in that inner while-loop, but since they
> > never change, they'll never match unless they happen to start out as
> > matched.
>
> > you need to re-evaluate str_time each time through the loop.  Make a
> > copy of that statement and put it inside the loop.
>
> > You probably don't want those loops to be comparing to ==, though, since
> > if you start this script on some other day, it'll never loop at all.
> > Also, it'd be good to do some form of sleep() function when you're
> > waiting, so you don't bog the system down with a busy-loop.
>
> > DaveA
>
> i guess im just having a hard time creating something like
> check if go condition,
> else sleep
>
> the double while loops take 12% cpu usage on my machine so this is
> probably unacceptable.
> also the sleep command does not like me :
>  >>> from datetime import *
>
> >>> from time import strftime,localtime,sleep
> >>> time.sleep(3)
>
> Traceback (most recent call last):
>   File "", line 1, in 
>     time.sleep(3)
> AttributeError: type object 'datetime.time' has no attribute 'sleep'
>
>
>
> here it is updated with the hour/min check fixed.
> #updated python code
> import os,string,time,getpass,md5,ConfigParser
> from datetime import *
> from os.path import join, getsize
> from time import strftime,localtime,sleep
>
> config = ConfigParser.ConfigParser()
> config.read("config.ini")
> date = config.get("myvars", "date")
> time = config.get("myvars", "time")
>
> while datetime.now().weekday() == int(date):
>     str_time=strftime("%H:%M",localtime())
>     while str_time == time:
>         print "do it"

i think this is what you are talking about
except that the time.sleep just does not work.
even changing "from time import strftime,localtime" to "from time
import strftime,localtime,sleep" does not do it.
#python code
import os,string,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime

config = ConfigParser.ConfigParser()
config.read("config.ini")
date = config.get("myvars", "date")
time = config.get("myvars", "time")

a=1
while a>0:
if datetime.now().weekday() == int(date):
str_time=strftime("%H:%M",localtime())
if str_time == time:
print "do it"
time.sleep(58)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread MRAB

On 21/03/2011 02:48, ecu_jon wrote:

On Mar 20, 10:09 pm, Dave Angel  wrote:

On 01/-10/-28163 02:59 PM, ecu_jon wrote:




I'm working on a script that will run all the time. at time specified
in a config file, will kick-off a backup.
problem is, its not actually starting the job. the double while loop
runs, the first comparing date works. the second for hour/min does
not.



#python file
import os,string,,time,getpass,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime



config = ConfigParser.ConfigParser()
config.read("config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
date = config.get("myvars", "date")
time = config.get("myvars", "time")
str_time=strftime("%H:%M",localtime())



while datetime.now().weekday() == int(date):
  while str_time == time:
  print "do it"


You're comparing two objects in that inner while-loop, but since they
never change, they'll never match unless they happen to start out as
matched.

you need to re-evaluate str_time each time through the loop.  Make a
copy of that statement and put it inside the loop.

You probably don't want those loops to be comparing to ==, though, since
if you start this script on some other day, it'll never loop at all.
Also, it'd be good to do some form of sleep() function when you're
waiting, so you don't bog the system down with a busy-loop.

DaveA


i guess im just having a hard time creating something like
check if go condition,
else sleep

the double while loops take 12% cpu usage on my machine so this is
probably unacceptable.


I would calculate the amount of time until the next event and then
sleep for that amount of time.


also the sleep command does not like me :
  >>>  from datetime import *


This imports everything (well, almost everything) that's in the
datetime module. One of those things is called "time".

Importing everything like this is not recommended because it 'pollutes'
the namespace.


from time import strftime,localtime,sleep


This imports 3 items from the time module, but the name "time" itself
still refers to what was imported by the previous line.


time.sleep(3)


Traceback (most recent call last):
   File "", line 1, in
 time.sleep(3)
AttributeError: type object 'datetime.time' has no attribute 'sleep'





This tells you that "time" (which you imported from the datetime
module) is a class in the datetime module.

You imported "sleep" from the time module, so refer to it as "sleep".


here it is updated with the hour/min check fixed.
#updated python code
import os,string,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime,sleep

config = ConfigParser.ConfigParser()
config.read("config.ini")
date = config.get("myvars", "date")
time = config.get("myvars", "time")

while datetime.now().weekday() == int(date):
 str_time=strftime("%H:%M",localtime())
 while str_time == time:
 print "do it"

--
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread MRAB

On 21/03/2011 03:29, ecu_jon wrote:

On Mar 20, 10:48 pm, ecu_jon  wrote:

On Mar 20, 10:09 pm, Dave Angel  wrote:




On 01/-10/-28163 02:59 PM, ecu_jon wrote:



I'm working on a script that will run all the time. at time specified
in a config file, will kick-off a backup.
problem is, its not actually starting the job. the double while loop
runs, the first comparing date works. the second for hour/min does
not.



#python file
import os,string,,time,getpass,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime



config = ConfigParser.ConfigParser()
config.read("config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
date = config.get("myvars", "date")
time = config.get("myvars", "time")
str_time=strftime("%H:%M",localtime())



while datetime.now().weekday() == int(date):
  while str_time == time:
  print "do it"



You're comparing two objects in that inner while-loop, but since they
never change, they'll never match unless they happen to start out as
matched.



you need to re-evaluate str_time each time through the loop.  Make a
copy of that statement and put it inside the loop.



You probably don't want those loops to be comparing to ==, though, since
if you start this script on some other day, it'll never loop at all.
Also, it'd be good to do some form of sleep() function when you're
waiting, so you don't bog the system down with a busy-loop.



DaveA


i guess im just having a hard time creating something like
check if go condition,
else sleep

the double while loops take 12% cpu usage on my machine so this is
probably unacceptable.
also the sleep command does not like me :
  >>>  from datetime import *


from time import strftime,localtime,sleep
time.sleep(3)


Traceback (most recent call last):
   File "", line 1, in
 time.sleep(3)
AttributeError: type object 'datetime.time' has no attribute 'sleep'



here it is updated with the hour/min check fixed.
#updated python code
import os,string,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize
from time import strftime,localtime,sleep

config = ConfigParser.ConfigParser()
config.read("config.ini")
date = config.get("myvars", "date")
time = config.get("myvars", "time")

while datetime.now().weekday() == int(date):
 str_time=strftime("%H:%M",localtime())
 while str_time == time:
 print "do it"


i think this is what you are talking about
except that the time.sleep just does not work.
even changing "from time import strftime,localtime" to "from time
import strftime,localtime,sleep" does not do it.
#python code
import os,string,time,getpass,md5,ConfigParser


At this point, "time" refers to the time module which you have just
imported.


from datetime import *


At this point, "time" refers to the class "time" which you have just
imported from the datetime module.


from os.path import join, getsize
from time import strftime,localtime

config = ConfigParser.ConfigParser()
config.read("config.ini")
date = config.get("myvars", "date")
time = config.get("myvars", "time")


At this point, "time" refers to the value you got from the config.


a=1
while a>0:
 if datetime.now().weekday() == int(date):
 str_time=strftime("%H:%M",localtime())


At this point, "time" still refers to the value you got from the config.


 if str_time == time:
 print "do it"


At this point, "time" still refers to the value you got from the config.
It does not have an attribute called "sleep".


 time.sleep(58)


--
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread ecu_jon
so then why does this not work ?

from datetime import datetime
from os.path import join, getsize
import time,os,string,getpass,md5,ConfigParser
from time import strftime,localtime

config = ConfigParser.ConfigParser()
config.read("config.ini")
date = config.get("myvars", "date")
time = config.get("myvars", "time")
#print "date is ",date , " time is ",time
a=1
while a>0:
#import time
time.sleep(2)
if datetime.now().weekday() == int(date):
str_time=strftime("%H:%M",localtime())
print "do it"

Traceback (most recent call last):
  File "I:\college\spring11\capstone-project\time-test.py", line 25,
in 
time.sleep(2)
AttributeError: 'str' object has no attribute 'sleep'
>>>

if i uncomment the import time line in the while loop it works.
boggle...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread eryksun ()
On Monday, March 21, 2011 12:07:13 AM UTC-4, ecu_jon wrote:
> so then why does this not work ?
>
> import time
> ...
> time = config.get("myvars", "time")
> ...
> while a>0:
> #import time
> time.sleep(2)
> 
> if i uncomment the import time line in the while loop it works.
> boggle...

An imported module is an object:

>>> import time
>>> repr(time)
""

>>> dir(time)
['__doc__', '__name__', '__package__', 'accept2dyear', 
'altzone', 'asctime', 'clock', 'ctime', 'daylight', 
'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 
'strptime', 'struct_time', 'time', 'timezone', 'tzname']

In Python variables are references to objects. for example, you could do the 
following:

>>> import time as foo
>>> repr(foo)
""

>>> dir(foo)
['__doc__', '__name__', '__package__', 'accept2dyear', 
'altzone', 'asctime', 'clock', 'ctime', 'daylight', 
'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 
'strptime', 'struct_time', 'time', 'timezone', 'tzname']

When you execute 'time = config.get("myvars", "time")', the variable "time" now 
references a string object instead of the module.  Strings don't 'sleep'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread Nick Stinemates
You should just use cron (or Windows Scheduled Tasks if that's your thing)
for job scheduling, allowing people the flexibility of the environment they
already know.

Nick

On Sun, Mar 20, 2011 at 6:19 PM, ecu_jon  wrote:

> I'm working on a script that will run all the time. at time specified
> in a config file, will kick-off a backup.
> problem is, its not actually starting the job. the double while loop
> runs, the first comparing date works. the second for hour/min does
> not.
>
> #python file
> import os,string,,time,getpass,ConfigParser
> from datetime import *
> from os.path import join, getsize
> from time import strftime,localtime
>
> config = ConfigParser.ConfigParser()
> config.read("config.ini")
> source = config.get("myvars", "source")
> destination = config.get("myvars", "destination")
> date = config.get("myvars", "date")
> time = config.get("myvars", "time")
> str_time=strftime("%H:%M",localtime())
>
> while datetime.now().weekday() == int(date):
>while str_time == time:
>print "do it"
>
> #config file
> #change the time variable to "now"+a min or two to observe
> #this needs to be where ever the actual python script is
> [myvars]
> #only set source if you want it to be different
> source: c:\users\jon
> destination: \\mothera\jon\
> #what day of the week to perform backup?where Monday is 0 and Sunday
> is 6
> date: 6
> #time to start
> time: 21:02
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reimport module every n seconds

2011-03-20 Thread John Nagle

On 3/17/2011 3:53 PM, Aahz wrote:

In article<753e9884-60eb-43cf-a647-12b29ed28...@y31g2000prd.googlegroups.com>,
Santiago Caracol  wrote:

Don't do that. =A0;-) =A0I suggest using exec instead. =A0However, I wo=

uld be

surprised if import worked faster than, say, JSON (more precisely, I
doubt that it's enough faster to warrnat this kludge).


I'm with Aahz. =A0Don't do that.

>>

I didn't find a good way to calculate and compile the regular
expressions once and store them.


   Hm. Regular expression compilation in CPython happens when
you call "re.compile", not when .pyc files are generated.
You can call "re.compile" on strings read from an external
source without loading a new module.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: python time

2011-03-20 Thread ecu_jon
i see. i was using time as a variable name , messing it all up.im not
going to post the whole backup script here, but here are a few lines
that i changed to make it work.

from datetime import datetime
from os.path import join, getsize
import time,os,string,getpass,md5,ConfigParser
from time import strftime,localtime
hrmin = config.get("myvars", "hrmin") #was time =, this is what did
it.
while a>0:
if datetime.now().weekday() == int(date):
str_time=strftime("%H:%M",localtime())
if str_time == hrmin:
print "do it"
 os.system(cmd)
time.sleep(5)#will prolly want to change to to 30 or higher for
release file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted and txJSON-RPC

2011-03-20 Thread Travis
This problem has come up for me as well.

$ sudo easy_install pylisp-ng
[sudo] password for _: 
install_dir /usr/local/lib/python2.6/dist-packages/
Searching for pylisp-ng
Reading http://pypi.python.org/simple/pylisp-ng/
Reading https://launchpad.net/pylisp-ng
Best match: pyLisp-NG 2.0.0
Downloading 
http://pypi.python.org/packages/source/p/pyLisp-NG/pyLisp-NG-2.0.0.tar.gz#md5=84141318cde6bf4e4f10ac4a920531be
Processing pyLisp-NG-2.0.0.tar.gz
Running pyLisp-NG-2.0.0/setup.py -q bdist_egg --dist-dir 
/tmp/easy_install-N3JX01/pyLisp-NG-2.0.0/egg-dist-tmp-CpmhdK
error: docs/PRELUDE.txt: No such file or directory
-- 
http://mail.python.org/mailman/listinfo/python-list