GET MORE FOR YOUR BUCK

2005-03-14 Thread ml
The biggest store online

www.thebuckstore.com
http://www.thebuckstore.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-19 Thread Satish ML
On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote:
> On Mon, May 19, 2014 at 4:53 PM,  wrote: > Could 
> you kindly help? Sure. Either start writing code and then post when you have 
> problems, or investigate some shell commands (xcopy in Windows, cp in Linux, 
> maybe scp) that can probably do the whole job. Or pay someone to do the job 
> for you. ChrisA

Consider xls file contains source and destination directory paths.
import xlrd, sys, subprocess
file_location = "C:\Users\User1\Desktop\input.xls"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
sheet.cell_value(0, 0)
for row in range(sheet.nrows):
  
values = []
   
values.append(sheet.cell_value(row, 1))

  
destination = []
destination.append(sheet.cell_value(row, 2))


for s in values:

for d in destination:
   What next after this? 
shutil.copy(src, dest) doesn't work because it overwrites dest files.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-19 Thread Satish ML
On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote:
> On Mon, May 19, 2014 at 4:53 PM,  wrote: > Could 
> you kindly help? Sure. Either start writing code and then post when you have 
> problems, or investigate some shell commands (xcopy in Windows, cp in Linux, 
> maybe scp) that can probably do the whole job. Or pay someone to do the job 
> for you. ChrisA

Hi ChrisAngelico,

Consider that source and destination directories are given in a .xls(excel) 
file.

This is the code

import xlrd, sys, subprocess
file_location = "C:\Users\salingeg\Desktop\input.xls"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
sheet.cell_value(0, 0)
for row in range(sheet.nrows):
  
values = []
   
values.append(sheet.cell_value(row, 1))

  
destination = []
destination.append(sheet.cell_value(row, 2))


for s in values:

for d in destination:


If I am using cp or xcopy command, it will copy all files from s to d.
shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly 
help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-20 Thread Satish ML
On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote:
> On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On 
> Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 
> 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 
> at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code 
> and then post when you have problems, or investigate some shell commands 
> (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole 
> job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > 
> Consider that source and destination directories are given in a .xls(excel) 
> file. > This is the code > import xlrd, sys, subprocess > file_location = 
> "C:\Users\salingeg\Desktop\input.xls" > workbook = 
> xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > 
> sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > 
> values.append(sheet.cell_value(row, 1)) > destination = [] > 
> destination.append(sheet.cell_value(row, 2)) > for s in values: > for
  d in destination: > If I am using cp or xcopy command, it will copy all files 
from s to d. > shutil.copy(s, d) can't be used here because it overwrites files 
in d. Kindly help. have u tried using 
https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried 
it. But how does it help? We won't be able to make out whether source file is 
present in destination directory.

If we can do that, like

if (source file exists in destination directory)
print "exists"
else
shutil.copy(s, d)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-20 Thread Satish ML
On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote:
> On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, 
> May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 
> 2014 at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing 
> code and then post when you have problems, or investigate some shell commands 
> (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole 
> job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > 
> Consider that source and destination directories are given in a .xls(excel) 
> file. > This is the code > import xlrd, sys, subprocess > file_location = 
> "C:\Users\salingeg\Desktop\input.xls" > workbook = 
> xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > 
> sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > 
> values.append(sheet.cell_value(row, 1)) > destination = [] > 
> destination.append(sheet.cell_value(row, 2)) > for s in values: > for d in 
> destination: > If I am using cp or xcopy command, it will copy
  all files from s to d. > shutil.copy(s, d) can't be used here because it 
overwrites files in d. Kindly help. have u tried using 
https://docs.python.org/2/library/os.path.html#os.path.exists ?

I have tried it. But how does it help?

We won't be able to make out whether source file is present in destination 
directory.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-20 Thread Satish ML
On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote:
> On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On 
> Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 
> 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 
> at 4:53 PM, wrote: > Could you kindly help? Sure. Either start writing code 
> and then post when you have problems, or investigate some shell commands 
> (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole 
> job. Or pay someone to do the job for you. ChrisA > Hi ChrisAngelico, > 
> Consider that source and destination directories are given in a .xls(excel) 
> file. > This is the code > import xlrd, sys, subprocess > file_location = 
> "C:\Users\salingeg\Desktop\input.xls" > workbook = 
> xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > 
> sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > 
> values.append(sheet.cell_value(row, 1)) > destination = [] > 
> destination.append(sheet.cell_value(row, 2)) > for s in values: > for
  d in destination: > If I am using cp or xcopy command, it will copy all files 
from s to d. > shutil.copy(s, d) can't be used here because it overwrites files 
in d. Kindly help. have u tried using 
https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried 
it. But how does it help? We won't be able to make out whether source file is 
present in destination directory.

If we can do that, like 

if (source file exists in destination directory) 
 print "exists" 
 continue
else 
 shutil.copy(s, d) 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-20 Thread Satish ML
On Tuesday, May 20, 2014 5:54:47 PM UTC+5:30, Satish ML wrote:
> On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On Tuesday, 
> May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 
> 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 
> PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, 
> wrote: > Could you kindly help? Sure. Either start writing code and then post 
> when you have problems, or investigate some shell commands (xcopy in Windows, 
> cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to 
> do the job for you. ChrisA > Hi ChrisAngelico, > Consider that source and 
> destination directories are given in a .xls(excel) file. > This is the code > 
> import xlrd, sys, subprocess > file_location = 
> "C:\Users\salingeg\Desktop\input.xls" > workbook = 
> xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > 
> sheet.cell_value(0, 0) > for row in range(sheet.nrows): > values = [] > 
> values.append(sheet.cell_value(row, 1)) > destination = [] > dest
 ination.append(sheet.cell_value(row, 2)) > for s in values: > for d in 
destination: > If I am using cp or xcopy command, it will copy all files from s 
to d. > shutil.copy(s, d) can't be used here because it overwrites files in d. 
Kindly help. have u tried using 
https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried 
it. But how does it help? We won't be able to make out whether source file is 
present in destination directory. If we can do that, like if (source file 
exists in destination directory) print "exists" continue else shutil.copy(s, d)

Here we don't have the option of manually giving the file path. It has to be 
read from .xls file (i.e. from the two lists in code)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of sa

2014-05-21 Thread Satish ML
On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, Rustom Mody wrote:
> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar 
> wrote: > Hi Satish, > > Can you please send python part in plain text format? 
> Python code here is > > difficult to read. It would be helpful to read 
> https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups 
> Note particularly the 2 standard expectations: - Dont top post - Dont use 
> excessively long (> 70 chars) lines

Hi,

Here is the code.


xls file looks as follows:
a.c C:\Desktop\salingeg\src\code\a.cC:\Desktop\salingeg\dest\code
hello.txt   C:\Desktop\salingeg\src\txt\hello.txt   
C:\Desktop\salingeg\dest\txt
integration.doc C:\Desktop\salingeg\src\doc\integration.doc 
C:\Desktop\salingeg\dest\doc
UG.doc  C:\Desktop\salingeg\src\doc\UG.doc  C:\Desktop\salingeg\dest\doc
Applications.xmlC:\Desktop\salingeg\src\xml\Applications.xml
C:\Desktop\salingeg\dest\xml
Platforms.xml   C:\Desktop\salingeg\src\xml\Platforms.xml   
C:\Desktop\salingeg\dest\xml
avc.alias   C:\Desktop\salingeg\src\cnx\alias\avc.alias 
C:\Desktop\salingeg\dest\cnx\alias
cats.alias  C:\Desktop\salingeg\src\cnx\alias\cats.alias
C:\Desktop\salingeg\dest\cnx\alias
avc.initC:\Desktop\salingeg\src\cnx\init\avc.init   
C:\Desktop\salingeg\dest\cnx\init
cats.init   C:\Desktop\salingeg\src\cnx\init\cats.init  
C:\Desktop\salingeg\dest\cnx\init


PYTHON SCRIPT:

import xlrd, sys, os, shutil

file_location = "C:\Users\salingeg\Desktop\input.xls"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
sheet.cell_value(0, 0)
for row in range(sheet.nrows):
source = []
source.append(sheet.cell_value(row, 1))
destination = []
destination.append(sheet.cell_value(row, 2))
files = []
files.append(sheet.cell_value(row, 0))
for f in files:
for s in source:
for d in destination:
print f
print s
print d
if (os.path.exists("d\\f")):
print ('File exists')
else:
shutil.copy(s, d)

I am getting the following error:

a.c
C:\Desktop\salingeg\src\code\a.c
C:\Desktop\salingeg\dest\code
Traceback (most recent call last):
  File "C:\Users\salingeg\Desktop\excel_1.py", line 24, in 
shutil.copy(s, d)
  File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy
copyfile(src, dst)
  File "C:\Program Files (x86)\python26\lib\shutil.py", line 50, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 
u'C:\\Desktop\\salingeg\\src\\code\\a.c'


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


Re: Copying non-existing files, was Re: Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without over

2014-05-21 Thread Satish ML
On Wednesday, May 21, 2014 2:42:49 PM UTC+5:30, Peter Otten wrote:
> Satish ML wrote: [Regarding subject: let's see if we can trigger a buffer 
> overflow somewhere ;)] > On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, 
> Rustom Mody wrote: >> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh 
> N. Malakannavar >> wrote: > Hi Satish, > > Can you please send python part in 
> plain text >> format? Python code here is > > difficult to read. It would be 
> helpful to >> read >> 
> https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups >> 
> Note particularly the 2 standard expectations: - Dont top post - Dont use >> 
> excessively long (> 70 chars) lines > > Hi, > > Here is the code. > > > xls 
> file looks as follows: > a.c C:\Desktop\salingeg\src\code\a.c 
> C:\Desktop\salingeg\dest\code > hello.txt 
> C:\Desktop\salingeg\src\txt\hello.txt > C:\Desktop\salingeg\dest\txt > 
> integration.doc C:\Desktop\salingeg\src\doc\integration.doc > 
> C:\Desktop\salingeg\dest\doc > UG.doc C:\Desktop\salingeg\src\doc\UG.doc 
> C:\Desktop\salingeg\dest\doc > Applications.xml C:\De
 sktop\salingeg\src\xml\Applications.xml > C:\Desktop\salingeg\dest\xml > 
Platforms.xml C:\Desktop\salingeg\src\xml\Platforms.xml > 
C:\Desktop\salingeg\dest\xml > avc.alias 
C:\Desktop\salingeg\src\cnx\alias\avc.alias > 
C:\Desktop\salingeg\dest\cnx\alias > cats.alias 
C:\Desktop\salingeg\src\cnx\alias\cats.alias > 
C:\Desktop\salingeg\dest\cnx\alias > avc.init 
C:\Desktop\salingeg\src\cnx\init\avc.init > C:\Desktop\salingeg\dest\cnx\init > 
cats.init C:\Desktop\salingeg\src\cnx\init\cats.init > 
C:\Desktop\salingeg\dest\cnx\init > > > PYTHON SCRIPT: > > import xlrd, sys, 
os, shutil > > file_location = "C:\Users\salingeg\Desktop\input.xls" > workbook 
= xlrd.open_workbook(file_location) > sheet = workbook.sheet_by_index(0) > 
sheet.cell_value(0, 0) > for row in range(sheet.nrows): > source = [] > 
source.append(sheet.cell_value(row, 1)) > destination = [] > 
destination.append(sheet.cell_value(row, 2)) > files = [] > 
files.append(sheet.cell_value(row, 0)) > for f in files: > for s in source: > 
 for d in destination: > print f > print s > print d > if 
(os.path.exists("d\\f")): The following line will either always be executed if 
you have a subdirectory "d" in your current working directory and that 
directory contains a file called "f" (unlikely) or never if "d\\f" doesn't 
exist (likely). Have a look at os.path.join() for the right way to join a 
directory with a filename into a path. Use the interactive interpreter to make 
sure you get the desired result and understand how it works before you fix your 
script. > print ('File exists') > else: > shutil.copy(s, d) > > I am getting 
the following error: > > a.c > C:\Desktop\salingeg\src\code\a.c > 
C:\Desktop\salingeg\dest\code > Traceback (most recent call last): > File 
"C:\Users\salingeg\Desktop\excel_1.py", line 24, in  > shutil.copy(s, 
d) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy > 
copyfile(src, dst) > File "C:\Program Files (x86)\python26\lib\shutil.py", line 
50, in > copyfile > with open
 (src, 'rb') as fsrc: > IOError: [Errno 2] No such file or directory: > 
u'C:\\Desktop\\salingeg\\src\\code\\a.c' According to the error message the 
file you are trying to copy doesn't exist. Have a look into the 
C:\Desktop\salngeg\src\code folder, and check whether a file called a.c is 
there. If not you have three options - add the file - remove the line from the 
excel file - modify the code to check if the *source* file exists

Hi,


On Wednesday, May 21, 2014 2:42:49 PM UTC+5:30, Peter Otten wrote:
> Satish ML wrote: [Regarding subject: let's see if we can trigger a buffer 
> overflow somewhere ;)] > On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, 
> Rustom Mody wrote: >> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh 
> N. Malakannavar >> wrote: > Hi Satish, > > Can you please send python part in 
> plain text >> format? Python code here is > > difficult to read. It would be 
> helpful to >> read >> 
> https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups >> 
> Note particularly the 2 standard expectations: - Dont top post - Dont use >> 
> excessively long (> 70 chars) lines > > Hi, > > Here is the code. > > > xls 
> file looks as follows: > a.c C:\Desktop\salingeg\src\code\a.c 
> C:\Desktop\salingeg\dest\code > hello.txt 
> C:\Desktop\saling

Return class.

2014-07-26 Thread Satish ML
Hi,

What does "return Wrapper" do in the following piece of code? Which method does 
it invoke?
I mean "return Wrapper" invokes __init__ method?

def Tracer(aClass):
class Wrapper:
def __init__(self, *args, **kargs):
self.fetches = 0
self.wrapped = aClass(*args, **kargs)
def __getattr__(self, attrname):
print('Trace: ' + attrname)
self.fetches += 1
print(self.fetches)
return getattr(self.wrapped, attrname)
return Wrapper


Actual program:

def Tracer(aClass):
class Wrapper:
def __init__(self, *args, **kargs):
self.fetches = 0
self.wrapped = aClass(*args, **kargs)
def __getattr__(self, attrname):
print('Trace: ' + attrname)
self.fetches += 1
print(self.fetches)
return getattr(self.wrapped, attrname)
return Wrapper
@Tracer
class Spam:
def __init__(self, *args):
print(*args)
def display(self):
print('Spam!' * 8)

@Tracer
class Person:
def __init__(self, name, hours, rate):
self.name = name
self.hours = hours
self.rate = rate
def pay(self):
return self.hours * self.rate

food = Spam("CARST")
food.display()
print([food.fetches])

bob = Person('Bob', 40, 50)
print(bob.name)
print(bob.pay())

print('')
sue = Person('Sue', rate=100, hours=60)
print(sue.name)
print(sue.pay())

print(bob.name)
print(bob.pay())
print([bob.fetches, sue.fetches])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Return class.

2014-07-26 Thread Satish ML
Which line of code is printing [4] and [4, 5, 6, 7] in the output?

from tracer import Tracer
@Tracer
class MyList(list):
def __init__(self, *args):
print("INSIDE MyList")
print(*args)
x = MyList([1, 2, 3])
x.append(4)
print(x.wrapped)
WrapList = Tracer(list)
x = WrapList([4, 5, 6])
x.append(7)
print(x.wrapped)

OUTPUT:

CARST
Trace: display
1
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
[1]
Trace: name
1
Bob
Trace: pay
2
2000

Trace: name
1
Sue
Trace: pay
2
6000
Trace: name
3
Bob
Trace: pay
4
2000
[4, 2]
INSIDE MyList
[1, 2, 3]
Trace: append
1
[4]
Trace: append
1
[4, 5, 6, 7]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Return class.

2014-07-26 Thread Satish ML
Which line of code is printing [4] and [4, 5, 6, 7] in the output?

from tracer import Tracer
@Tracer
class MyList(list):
def __init__(self, *args):
print("INSIDE MyList")
print(*args)
x = MyList([1, 2, 3])
x.append(4)
print(x.wrapped)
WrapList = Tracer(list)
x = WrapList([4, 5, 6])
x.append(7)
print(x.wrapped)

OUTPUT:

CARST
Trace: display
1
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
[1]
Trace: name
1
Bob
Trace: pay
2
2000

Trace: name
1
Sue
Trace: pay
2
6000
Trace: name
3
Bob
Trace: pay
4
2000
[4, 2]
INSIDE MyList
[1, 2, 3]
Trace: append
1
[4]
Trace: append
1
[4, 5, 6, 7]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Return class.

2014-07-26 Thread Satish ML
Which line of code is printing [4] and [4, 5, 6, 7] in the output?

from tracer import Tracer
@Tracer
class MyList(list):
def __init__(self, *args):
print("INSIDE MyList")
print(*args)
x = MyList([1, 2, 3])
x.append(4)
print(x.wrapped)
WrapList = Tracer(list)
x = WrapList([4, 5, 6])
x.append(7)
print(x.wrapped)

OUTPUT:

CARST
Trace: display
1
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
[1]
Trace: name
1
Bob
Trace: pay
2
2000

Trace: name
1
Sue
Trace: pay
2
6000
Trace: name
3
Bob
Trace: pay
4
2000
[4, 2]
INSIDE MyList
[1, 2, 3]
Trace: append
1
[4]
Trace: append
1
[4, 5, 6, 7]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Return class.

2014-07-26 Thread Satish ML
Actual program: 

def Tracer(aClass): 
class Wrapper: 
def __init__(self, *args, **kargs): 
self.fetches = 0 
self.wrapped = aClass(*args, **kargs) 
def __getattr__(self, attrname): 
print('Trace: ' + attrname) 
self.fetches += 1 
print(self.fetches) 
return getattr(self.wrapped, attrname) 
return Wrapper 
@Tracer 
class Spam: 
def __init__(self, *args): 
print(*args) 
def display(self): 
print('Spam!' * 8) 

@Tracer 
class Person: 
def __init__(self, name, hours, rate): 
self.name = name 
self.hours = hours 
self.rate = rate 
def pay(self): 
return self.hours * self.rate 

food = Spam("CARST") 
food.display() 
print([food.fetches]) 

bob = Person('Bob', 40, 50) 
print(bob.name) 
print(bob.pay()) 

print('') 
sue = Person('Sue', rate=100, hours=60) 
print(sue.name) 
print(sue.pay()) 

print(bob.name) 
print(bob.pay()) 
print([bob.fetches, sue.fetches]) 


Which line of code is printing [4] and [4, 5, 6, 7] in the output? 
Another module.
from tracer import Tracer 
@Tracer 
class MyList(list): 
def __init__(self, *args): 
print("INSIDE MyList") 
print(*args) 
x = MyList([1, 2, 3]) 
x.append(4) 
print(x.wrapped) 
WrapList = Tracer(list) 
x = WrapList([4, 5, 6]) 
x.append(7) 
print(x.wrapped) 

OUTPUT: 

CARST 
Trace: display 
1 
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam! 
[1] 
Trace: name 
1 
Bob 
Trace: pay 
2 
2000 

Trace: name 
1 
Sue 
Trace: pay 
2 
6000 
Trace: name 
3 
Bob 
Trace: pay 
4 
2000 
[4, 2] 
INSIDE MyList 
[1, 2, 3] 
Trace: append 
1 
[4] 
Trace: append 
1 
[4, 5, 6, 7] 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Return class.

2014-07-26 Thread Satish ML
Hi,

Which lines of code prints [4] and [4, 5, 6, 7] in the output?


Output:

CARST
Trace: display
1
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
[1]
Trace: name
1
Bob
Trace: pay
2
2000

Trace: name
1
Sue
Trace: pay
2
6000
Trace: name
3
Bob
Trace: pay
4
2000
[4, 2]
INSIDE MyList
[1, 2, 3]
Trace: append
1
[4]
Trace: append
1
[4, 5, 6, 7]

Actual Code:
def Tracer(aClass):
class Wrapper:
def __init__(self, *args, **kargs):
self.fetches = 0
self.wrapped = aClass(*args, **kargs)
def __getattr__(self, attrname):
print('Trace: ' + attrname)
self.fetches += 1
print(self.fetches)
return getattr(self.wrapped, attrname)
return Wrapper
@Tracer
class Spam:
def __init__(self, *args):
print(*args)
def display(self):
print('Spam!' * 8)

@Tracer
class Person:
def __init__(self, name, hours, rate):
self.name = name
self.hours = hours
self.rate = rate
def pay(self):
return self.hours * self.rate

food = Spam("CARST")
food.display()
print([food.fetches])

bob = Person('Bob', 40, 50)
print(bob.name)
print(bob.pay())

print('')
sue = Person('Sue', rate=100, hours=60)
print(sue.name)
print(sue.pay())


Another module that is producing output:

from tracer import Tracer
@Tracer
class MyList(list):
def __init__(self, *args):
print("INSIDE MyList")
print(*args)
  
x = MyList([1, 2, 3])
x.append(4)
print(x.wrapped)
WrapList = Tracer(list)
x = WrapList([4, 5, 6])
x.append(7)
print(x.wrapped)
-- 
https://mail.python.org/mailman/listinfo/python-list


TypeError: 'NoneType' object is not callable

2014-07-28 Thread Satish ML
Hi,

TypeError: 'NoneType' object is not callable? Why this error and what is the 
solution?
Code:
class SuperMeta:
def __call__(self, classname, supers, classdict):
print('In SuperMeta.call: ', classname, supers, classdict, sep='\n...')
Class = self.__New__(classname, supers, classdict)
self.__Init__(Class, classname, supers, classdict)
class SubMeta(SuperMeta):
def __New__(self, classname, supers, classdict):
print('In SubMeta.new: ', classname, supers, classdict, sep='\n...')
return type(classname, supers, classdict)
def __Init__(self, Class, classname, supers, classdict):
print('In SubMeta init:', classname, supers, classdict, sep='\n...')
print('...init class object:', list(Class.__dict__.keys()))
class Eggs:
pass
print('making class')
class Spam(Eggs, metaclass=SubMeta()):
data = 1
def meth(self, arg):
pass
print('making instance')
X = Spam()

print('data:', X.data)
Output:
making class
In SuperMeta.call: 
...Spam
...(,)
...{'meth': , '__module__': 
'__main__', '__qualname__': 'Spam', 'data': 1}
In SubMeta.new: 
...Spam
...(,)
...{'meth': , '__module__': 
'__main__', '__qualname__': 'Spam', 'data': 1}
In SubMeta init:
...Spam
...(,)
...{'meth': , '__module__': 
'__main__', '__qualname__': 'Spam', 'data': 1}
...init class object: ['meth', '__module__', 'data', '__doc__']
making instance
Traceback (most recent call last):
  File "C:/Users/Satish/Desktop/Python/Metaclasses7.py", line 21, in 
X = Spam()
TypeError: 'NoneType' object is not callable
-- 
https://mail.python.org/mailman/listinfo/python-list


TypeError: 'bytes' object is not callable error while trying to converting to bytes.

2014-08-04 Thread Satish ML
Hi,


>>>import struct
>>>file = open('data.bin', 'rb')
>>>bytes = file.read()
>>> records = [bytes([char] * 8) for char in b'spam']
Traceback (most recent call last):
  File "", line 1, in 
records = [bytes([char] * 8) for char in b'spam']
  File "", line 1, in 
records = [bytes([char] * 8) for char in b'spam']
TypeError: 'bytes' object is not callable


If we code something like given below, it works.

>>> records = [([char] * 8) for char in b'spam']
>>> records
[[115, 115, 115, 115, 115, 115, 115, 115], [112, 112, 112, 112, 112, 112, 112, 
112], [97, 97, 97, 97, 97, 97, 97, 97], [109, 109, 109, 109, 109, 109, 109, 
109]]

Could you kindly help me resolve this problem of converting to bytes?
-- 
https://mail.python.org/mailman/listinfo/python-list


AttributeError: 'module' object has no attribute 'fork'

2014-08-06 Thread Satish ML
Hi,

Code:
import os, time
def child(pipeout):
zzz = 0
while True:
time.sleep(zzz)
msg = ('Spam %03d' % zzz).encode()
os.write(pipeout, msg)
zzz = (zzz+1) % 5
def parent():
pipein, pipeout = os.pipe()
if os.fork() == 0:
child(pipeout)
else:
while True:
line = os.read(pipein, 32)
print('Parent %d got [%s] at %s' % (os.getpid(), line, time.time()))
parent()

Output:
Traceback (most recent call last):
  File "C:/Python34/pipe1.py", line 17, in 
parent()
  File "C:/Python34/pipe1.py", line 11, in parent
if os.fork() == 0:
AttributeError: 'module' object has no attribute 'fork'

Why does this error appear? Module os provides fork(). How to solve this 
problem? Kindly help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [pypy-dev] A quick question for you!

2018-06-19 Thread William ML Leslie
On 18 June 2018 at 22:18, Etienne Robillard  wrote:
> Hi,
>
> Quick question: Does anyone of you know what is the effect of enabling
> gc.enable() in sitecustomize.py when using PyPy? Can it reduce latency for
> long-lived WSGI applications?
>

gc is enabled by default.  you only need to use gc.enable() if you
have earlier run gc.disable().

-- 
William Leslie

Notice:
Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely MAY reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to DENY YOU THOSE RIGHTS would be illegal without
prior contractual agreement.
-- 
https://mail.python.org/mailman/listinfo/python-list


how to use WSGI applications with apache

2009-10-07 Thread travis+ml-python
Hi folks,

I'm not quite sure where to ask this, but this is my closest guess.

I've written a web service based on the newf micro-framework and it uses
wsgiref.simple_server.  I'm noticing that it's not returning response
codes properly (after fixing a bug in newf).  Instead, it just
closes the TCP connection silently.

I am assuming that I need to run it with a more sophisticated server,
and I eventually want to run it under apache, but I can't seem to
figure out how to do this.  Someone once showed me how, and it was
a simple line in the apache config.  But I can't figure it out how
to do again.

Any help?
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpJzDE6lo3nC.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-15 Thread travis+ml-python
On Mon, May 10, 2010 at 08:45:51PM +0100, Nobody wrote:
> On Tue, 11 May 2010 00:24:22 +1200, Samuel Williams wrote:
> > Is Python a functional programming language?
> Not in any meaningful sense of the term.

LOL

> > I heard that lambdas were limited to a single expression,
> 
> Yes. In a functional language that wouldn't be a problem, as there's no
> limit to the complexity of an expression. Python's expressions are far
> more limited, which restricts what can be done with a lambda.

One very annoying thing in Python is the distinction between
statements and expressions.

Ever since learning LISP (well, Scheme) in S&ICP I find myself
frequently annoyed by this pointless distinction, started by
C (or earlier), and propogated without much thought.

Often I'll want to write a lamda that, say, prints something, or
modifies a global variable, and find that, well, it's either
impossible or beyond my interest in figuring it out.

It appears there is finally a ternary operator (for making if/else
into "expressions"):
http://en.wikipedia.org/wiki/Ternary_operation#Python
Maybe it will grow on me - it makes sense in English, but on
first glance I thought the programmer suffered from dyslexia.

To be fair, it appears that Python's whitespace-sensitive syntax sort
of precludes the "make a complex function on one line" that is typical
of languages which don't have statement/expression distinctions, but
I'm not convinced it couldn't be solved, perhaps by allowing anonymous
functions to span multiple lines, just like named functions.

> > Finally, even if Python supports functional features, is this a model that
> > is used often in client/application code?
> 
> Not really. List comprehensions are probably the most common example of
> functional idioms, but again they're limited by Python's rather limited
> concept of an expression.

Map/reduce, lambda, apply, that kind of stuff... kinda similar to
functional languages.

But "statements lack any side effects"?  No way.

In fact, a common distinction you'll see observed, but not always, is
that "statements may have side effects, expressions do not".

For some definitions of "functional language", there are no
side-effects, so there is no need for a statement which doesn't
evaluate to a value, so there is no need for a statement/expression
distinction, so everything is an expression.

You may have seen Paul Graham's other article about Python and LISP:
http://www.paulgraham.com/icad.html

Upon re-skimming it, I find myself wondering if I got the
expression/statement annoyance from his pages, or from my own
experience.  I can't remember :-) Probably it was an annoyance that I
hadn't put my finger on until he spelled it out for me, like a
splinter in my mind :-)

He obliquely references my other pet peeve, the global/class/local
distinction, completely ignoring arbitrarily-nested lexical scoping.
From what I've read in this thread, there's a recent "nonlocal"
declaration that sounds like it might accomplish something useful in
this regard.

(I still haven't figured out how he managed to use lexical closures in
 his web server to allow one web page to use another to allow the user
 to select and return a value, like a color from a color wheel, unless
 he implemented his own web server in LISP, since HTTP is stateless).

I really like Scheme's clean syntax (never learned Common LISP, sorry,
too much to remember) but frankly, I've never looked at a problem and
said, "you know, Scheme would be perfect for this".  Maybe if I was
writing a program that did optimizing transformations on abstract
syntax trees, or something.  And since Scheme has never come in handy,
I never bothered with Common LISP.  I feel similarly about ML, OCAML
and Haskell... maybe one day when I'm bored, not today, not this
project.

So in the end, I find myself using python more than anything else,
fully acknowledging its warts.  I used to admire its simplicity, but
now with decorators, iterators, generators, metaclasses, and the
proliferation of special method names, I have to wonder if that still
holds true...  certainly I understand 90+% of python programs, but
do I understand that proportion of the constructs?

PS: Why do people call LISP object-oriented?  Are they smoking crack?
No classes, no methods, no member variables... WTF?
-- 
A Weapon of Mass Construction
My emails do not have attachments; it's a digital signature that your mail
program doesn't understand. | http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpYyYI8jLDVr.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


pythonic web markup languages & templating systems & site generators

2010-06-05 Thread travis+ml-python
I started to review static blog-like HTML generators, and found myself
overwhelmed with how many there were.  I narrowed it down to pythonic
ones, and then realized I had to pick a markup language and templating
language, of which there are several pythonic implementations...

The results of my inquiry (still ongoing) are here:

http://www.subspacefield.org/~travis/static_blog_generators.html

It's a little disorganized, but does represent a fair amount of work,
and might be a nice intro for a python programmer who isn't up to
his neck in web authoring tools.

Suggestions on how to organize it are welcome.  Of course, while
writing it, I was struck by how much I actually needed one of these
systems to write the reviews of the systems :-) writing raw HTML
is teh suck.
-- 
A Weapon of Mass Construction
My emails do not have attachments; it's a digital signature that your mail
program doesn't understand. | http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpnVFtgT60rk.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


proposal: add setresuid() system call to python

2009-07-17 Thread travis+ml-python
Hello,

Historically, I have used scripting languages like python for typical
uses, but they tend to not fare very well at system programming; for
close interfacing with the operating system, I'm often forced to use a
language like C.  This is undesirable to me.

I do not think this has to be the case; I see no reason why a
scripting language can't implement more of the system call API, at the
risk of having some OS-dependent modules.  I would actually like to
see more network servers written in scripting languages, as they
neatly avoid buffer overflow and integer overflow issues with no extra
effort.

One BIG roadblock to doing this is when they can't manage to drop
permissions properly.

I am suggesting that the setresuid function be added to python,
perhaps in the OS module, because it has the clearest semantics for
manipulating user ids.  The reason why is best described in the
following paper:

http://www.eecs.berkeley.edu/~daw/papers/setuid-usenix02.pdf

One argument against this is that it is not specified by POSIX, and
thus might be dismissed as "implementation dependent".

However, as the paper above demonstrates, even though the setuid
system call is defined by POSIX, it already has system-dependent
behavior.  POSIX provides for at least two different behaviors of the
setuid call, and even more if you consider that it leaves what
constitutes "appropriate privileges" up to the OS kernel.

I humbly propose that python implement all the routines necessary to
securely drop privileges, to enable construction of network daemons
that might need to drop privileges from root to some non-root userid
(e.g. mail transfer agents, or POP/IMAP servers).

Furthermore, where there are multiple system calls to achieve this
effect, it should implement the ones with the clearest semantics, and
setresuid fits that bill.  To see what an utter mess the uid-manipulation
routines are in, I refer you once again to this paper, as the situation
is too complicated to describe in this email:

http://www.eecs.berkeley.edu/~daw/papers/setuid-usenix02.pdf

Opinions?

Best,
Travis
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpVyRpXxMRRP.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal: add setresuid() system call to python

2009-08-21 Thread travis+ml-python
On Mon, Jul 20, 2009 at 04:10:35PM +0200, Hrvoje Niksic wrote:
> To emulate the os-module-type calls, it's better to raise exceptions
> than return negative values:
> 
> > def setresuid(ruid, euid, suid):
> > return _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
> 
> def setresuid(ruid, euid, suid):
> res = _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
> if res < 0:
> raise OSError('[Errno %d] %s' % (os.errno, errno.strerror(os.errno)))

I am working on a module to implement all of this, but that raise command
won't work in Python 2.6.1; it turns out that os.errno is a module, not
an integer.  Does anyone know how to do what I want (that is, how to access
the errno set in C functions)?
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpCAmvYfWNJs.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal: add setresuid() system call to python

2009-08-25 Thread travis+ml-python
On Fri, Aug 21, 2009 at 03:13:12PM -0500, tra...@subspacefield.org wrote:
> Since the authors of the paper (Wagner et. al.) are proposing a new
> set of APIs to make all of this clearer, I'm thinking that I will
> create a module specifically for dropping permissions.

I've created the module here:

http://www.subspacefield.org/~travis/python/privilege/

I could sure use any comments people had on my python style.

PyPi link:
http://pypi.python.org/pypi/privilege/1.0
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpPM2rX9bRlM.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


run-time inclusion of files

2009-09-05 Thread travis+ml-python
Hello,

I was wondering if there was something like Perl's "require" that allows
you to import a file whose name is specified at run-time.  So far I've only
seen imports of modules that are put in the standard module include path.

I'm interested in three seperate problems:

1) being able to import a file that isn't in the standard module include path

2) being able to import a file whose name is specified in a python string

3) being able to reload the file if it changes on disk

I'm pretty sure that the Pylons web framework does all this, and I'm also
pretty sure that there's a simple solution, I am just not aware of what
it is.
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpPfqVqghzQh.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list