XMPP pub sub setup and working
I am using xmpppy python library to connect with XMPP server(ejabberd2) but
unable to connect and actually don't have clarity on how to connect,
authenticate and send a message to the server.
Please help me to make it working
If possible please provide some code snippet using XMPPPY.
This is what I have tried:
In [1]: from xmpp import Client
In [2]: cl = Client(server='176.9.18.111', 5280)
File "", line 1
cl = Client(server='176.9.18.111', 5280)
SyntaxError: non-keyword arg after keyword arg
In [3]: cl = Client(server='176.9.18.111', port =5280)
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for
/Users/gathole/.virtualenvs/driveu/lib/python2.7/site-packages/xmpp/client.py
DEBUG: flags defined: always,nodebuilder
In [4]: cl.connect()
DEBUG: socket start Plugging into
DEBUG: socket warn An error occurred while looking up
_xmpp-client._tcp.176.9.18.111
DEBUG: socket start Successfully connected to remote host
('176.9.18.111', 5280)
DEBUG: dispatcher start Plugging into
DEBUG: dispatcher info Registering namespace "unknown"
DEBUG: dispatcher info Registering protocol "unknown" as (unknown)
DEBUG: dispatcher info Registering protocol "default" as (unknown)
DEBUG: dispatcher info Registering namespace
"http://etherx.jabber.org/streams";
DEBUG: dispatcher info Registering protocol "unknown" as (http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering protocol "default" as (http://etherx.jabber.org/streams)
DEBUG: dispatcher info Registering namespace "jabber:client"
DEBUG: dispatcher info Registering protocol "unknown" as (jabber:client)
DEBUG: dispatcher info Registering protocol "default" as (jabber:client)
DEBUG: dispatcher info Registering protocol "iq" as (jabber:client)
DEBUG: dispatcher info Registering protocol "presence" as (jabber:client)
DEBUG: dispatcher info Registering protocol "message" as (jabber:client)
DEBUG: dispatcher info Registering handler > for "error" type-> ns->(http://etherx.jabber.org/streams)
DEBUG: dispatcher warn Registering protocol "error" as (http://etherx.jabber.org/streams)
DEBUG: socket sent
http://etherx.jabber.org/streams"; >
DEBUG: socket error Socket error while receiving data
DEBUG: client stop Disconnect detected
DEBUG: socket error Socket operation failed
Out[4]: ''
--
https://mail.python.org/mailman/listinfo/python-list
Can any body help me
how to write script for these 1.Given a test file containing lines of words such as (abc, abb, abd,abb, etc), write a script that prints, in order of frequency, how many times each word appears in the file. 2. Write a script running in an endless loop that pings an IP (specified on the command line) periodically. If the IP goes down n times in a row send one email message (to an address specified on the command line) that it's down (n is specified on the command line). Once it's available again n times in a row send an email that it's back up. When a specific signal is sent to the script it sends and email saying that it is shutting down and then exits thanx satish -- http://mail.python.org/mailman/listinfo/python-list
Pass variable by reference
Hello experts,
I have a burning question on how to pass variable by reference in Python. I
understand that the data type has to be mutable.
For example, here’s the issue I am running in to:
I am trying to extract the PostgreSQL DB version for example:
pgVer = [s.split() for s in os.popen("psql --version").read().splitlines()]
print pgVer[0]
for i, var in enumerate(pgVer[0]):
if i == len(pgVer[0]) - 1:
pgversion = var
I would now like to pass ‘pgversion’ (where the value of pgversion is 9.3.4) by
reference, for example:
I want to nuke /var/lib/postgresql/9.3.4/main/data , however programatically I
want it to be as: /var/lib/postgresql//main/data
Any help is appreciated.
Thanks
Satish--
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 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
passing Python assignment value to shell
Hello Experts,
I am trying to extract the available userspace+swap memory and then want to
feed this value as an argument to a tool that is executed in the shell.
so, this is what I have so far:
reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()]
freecalc_total = freecalc[4]
freecalc_total = freecalc_total[3]
freecalc_total = freecalc_total.translate(None, 'M’)
Now I want to feed the value for ‘freecalc_total’ as an argument to a command
executed by the shell.
For example:
devnull = open(os.devnull, “w”)
runCommand = subprocess.call([“stressapptest”, “”, “20”],stdout=devnull,stderr=subprocess.STDOUT)
devnull.close()
How do I go about doing this?
Many thanks in advance
-Satish--
https://mail.python.org/mailman/listinfo/python-list
Re: passing Python assignment value to shell
Hello Experts,
I was able to figure this out after spending time reading the Python help docs.
This is what I went about doing:
> reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()]
> freecalc_total = freecalc[4]
> freecalc_total = freecalc_total[3]
> freecalc_total = freecalc_total.translate(None, 'M’)
tmp = "%s" % freecalc_total
command = "stressapptest -M %s -s 20" % tmp
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()[0]
…
…
...
Please let me know if this is the optimal method to achieve in order to pass
the assignment value to shell. I am open to suggestions or a better way of
implementation/logic.
Thanks again
Satish
On May 28, 2014, at 1:16 PM, Satish Muthali wrote:
> Hello Experts,
>
> I am trying to extract the available userspace+swap memory and then want to
> feed this value as an argument to a tool that is executed in the shell.
>
> so, this is what I have so far:
>
> reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()]
> freecalc_total = freecalc[4]
> freecalc_total = freecalc_total[3]
> freecalc_total = freecalc_total.translate(None, 'M’)
>
> Now I want to feed the value for ‘freecalc_total’ as an argument to a command
> executed by the shell.
>
> For example:
>
> devnull = open(os.devnull, “w”)
> runCommand = subprocess.call([“stressapptest”, “ freecalc_total here>”, “20”],stdout=devnull,stderr=subprocess.STDOUT)
> devnull.close()
>
> How do I go about doing this?
>
> Many thanks in advance
>
> -Satish
--
https://mail.python.org/mailman/listinfo/python-list
Adding Bottle framework in existing python script
In my python script I am doing bluetooth and RF communication on individual
threads respectively. I want to add Rest Web Method in same script using Bottle
web framework.
If I add below code, in existing python script, it wont work. How to make it
work in existing script.
from bottle import Bottle, run
app = Bottle()
@app.route('/hello')
def hello():
return "Hello World!"
run(app, host='localhost', port=8080, debug = True)
--
https://mail.python.org/mailman/listinfo/python-list
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
Which is the best GTK
Hi all, I am a new one to python. I want which is the best gtk. Tkinter or Tix or etc., . Please suggest me some documentation. Thanks, Satish. Team Spiderace, www.spiderace.com. Send instant messages to your online friends http://in.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
What is the UI Element to work with HTML Content
Hi All, I am a newbie to Python. I want to know that there is any UI Control to browse HTML pages. Please let me know. If that is available, I am planing to develop a Chat application. Waiting for help. Thanks, Satish. [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] Send instant messages to your online friends http://in.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
XML RFC Server
Hi All, Is there any example code to develop XML RFC Web Service in Python. Thanks, Satish.Send instant messages to your online friends http://in.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
What is the method for class destroy
Hi All, Like __init__ which is called when object instatiated, what is the method when object destroys. Thanks, Satish.Send instant messages to your online friends http://in.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
how to handle jpg images with Tkinter
Hi, I am not able to load jpg images in photoimage widget. That is showing different different errors. can I find any examples on internet. Thanks, SatishSend instant messages to your online friends http://in.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Class Methods help
Thanks to Tim Chase & Lie Ryan !! That was exactly what I was looking for !! It's time for me to now read the documentation of "decorators" and @classmethod and also @staticmethod. I'm quite new to decorators... -- Satish BD On Sun, May 31, 2009 at 4:44 PM, Lie Ryan wrote: > bdsatish wrote: >> Hi, >> >> I have a question regarding the difference b/w "class methods" and >> "object methods". Consider for example: >> >> class MyClass: >> x = 10 >> >> Now I can access MyClass.x -- I want a similar thing for functions. I >> tried >> >> class MyClass: >> def some_func(x): >> return x+2 >> >> When I call MyClass.some_func(10) -- it fails, with error message: >> >> >> TypeError: unbound method some_func() must be called with MyClass >> instance as first argument (got int instance instead) >> >> OK. I figured out that something like this works: >> obj = MyClass() >> y = obj.some_func(10) >> >> BUT, this means that we have functions applying for instances. That is >> we have "instance method". Now, how do I implement some function which >> I can invoke with the class name itself ? Instead of creating a dummy >> object & then calling In short, how exactly do I create "class >> methods" ?? > with staticmethod decorator: > >>>> class MyClass: > ... @staticmethod > ... def some_func(x): > ... return x+2 > ... >>>> MyClass.some_func(10) > 12 > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Evaluating Income Property
Income property is becoming more attractive to investors looking for a better return on their money. With today's low interest rates, income- producing properties such as apartments and duplexes can produce exciting returns. As with any type of property, the value of income property is what someone is willing to pay for it. But, the main determinant of value for income property is the net income it will produce. As we'll see later, the income approach should closely correlate with the market value under normal market conditions. Buyers of residential income property will want to know the answers to several questions not normally asked by home buyers. First, what is the amount of cash flow the property will generate? Second, how much actual net income will it produce? Third, are the tax benefits that the property will provide the investor? Cash flow can be described as the amount of money collected as rental income each month. http://greatincomeproperties.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "isinstance" question
> >I want to test whether an object is an instance of any user-defined >> class. "isinstance" is less helpful than one would expect. >> >> >>> import types >> >>> class foo() : # define dummy class >> ... pass >> ... >> >>> x = foo() >> >>> >> >>> type(x) >> >> >>> >> >>> isinstance(x, types.ClassType) >> False >> >>> isinstance(x, types.InstanceType) >> True >> >>> foo >> >> >>> x >> <__main__.foo instance at 0x020080A8> >> >> So far, so good. x is an InstanceType. But let's try a >> class with a constructor: >> >> >>> class bar(object) : >> ...def __init__(self, val) : >> ... self.val = val >> ... >> >>> b = bar(100) >> >>> b >> <__main__.bar object at 0x01FF50D0> >> >>> isinstance(b, types.InstanceType) >> False >> >>> isinstance(b, types.ClassType) >> False >> >>>>>> bar >> >> >> well the same code on my side returns true when you run isinstance(b, types.InstanceType) even when the class has a constructor. Why is there a difference in the output when we are both using Cython 2.6 ?? (2.6.4 to be exact) Cheers Satish -- http://satisheerpini.net -- http://mail.python.org/mailman/listinfo/python-list
how do i configure Python2.3.6 on Solaris 10
following errors were found on executing configure file: 1) configure: WARNING: thread.h: present but cannot be compiled configure: WARNING: thread.h: check for missing prerequisite headers? configure: WARNING: thread.h: see the Autoconf documentation configure: WARNING: thread.h: section "Present But Cannot Be Compiled" configure: WARNING: thread.h: proceeding with the preprocessor's result configure: WARNING: thread.h: in the future, the compiler will take precedence 2) configure: WARNING: sys/wait.h: present but cannot be compiled configure: WARNING: sys/wait.h: check for missing prerequisite headers? configure: WARNING: sys/wait.h: see the Autoconf documentation configure: WARNING: sys/wait.h: section "Present But Cannot Be Compiled" configure: WARNING: sys/wait.h: proceeding with the preprocessor's result configure: WARNING: sys/wait.h: in the future, the compiler will take precedenceconfigure: WARNING: ## - ## configure: WARNING: ## Report this to the python lists. ## configure: WARNING: ## - ## Also no ./python executable is getting created on running make. -- http://mail.python.org/mailman/listinfo/python-list
