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
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
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
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
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
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
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
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
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.
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.
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.
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.
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.
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.
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
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.
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'
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
