Re: How do I list only the methods I define in a class?

2018-06-01 Thread bruceg113355
On Thursday, May 31, 2018 at 10:18:53 PM UTC-4, bob gailer wrote:
> On 5/31/2018 3:49 PM, bruceg113...@gmail.com wrote:
>  > How do I list only the methods I define in a class?
> Here's a class with some method, defined in various ways:
> 
>  >>> class x():
> ... a=3
> ... def f():pass
> ... g = lambda: None
> ...
> 
>  >>> l=[v for v in x.__dict__.items()]; print(l)
> [('a', 3), ('f', ), ('__module__', 
> '__main__'), ('__dict__', ), 
> ('__doc__', None), ('__weakref__',  objects>)]
> 
>  >>> import inspect
>  >>> [(key, value) for key, value in l if inspect.isfunction(i[1])]
> [('f', ), ('g',  
> at 0x01DEDD693620>)]
> 
> HTH




After more researching, I found the below code that works for me.

https://stackoverflow.com/questions/1911281/how-do-i-get-list-of-methods-in-a-python-class


from types import FunctionType

class Foo:
def bar(self): pass
def baz(self): pass

def methods(cls):
return [x for x, y in cls.__dict__.items() if type(y) == FunctionType]


Using the above code, I now get the following.
['__init__', 'apples', 'peaches', 'pumpkin']

Bruce

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


How do I list only the methods I define in a class?

2018-05-31 Thread bruceg113355
How do I list only the methods I define in a class?

For example:

class Produce():
def __init__ (self):
print (dir (Produce))

def apples(self):
pass

def peaches(self):
pass

def pumpkin (self):
pass

The print (dir(Produce)) statement displays:
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', 
'__str__', '__subclasshook__', '__weakref__', 'apples', 'peaches', 'pumpkin']

I am only interested in 'apples', 'peaches', 'pumpkin'

The above is only an example.
In my real code there are methods with and without leading "__". 

Can I assume methods after __weakref__ are the methods I defined?
Is there a Python function to do what I need?

Thanks,
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


convert a string to a variable

2018-05-24 Thread bruceg113355
I am trying to convert a string to a variable.

I got cases 1 & 2 to work, but not cases 3 & 4.

The print statement in cases 3 & 4 reports the following:
builtins.AttributeError: type object 'animal' has no attribute 'tiger'

I am stuck on creating variables that can be accessed as follows.
  animal.tiger
  self.animal.tiger

Any suggestions?

Thanks,
Bruce


# Tested on Python 3.6.5

# Case 1: This works
indata = 'animal_tiger'
vars()[indata] = "Tigers, big and strong!"
print (animal_tiger)


# Case 2: This works
class animal():
def create (self, indata):
vars(self)[indata] = "Tigers, big and strong!"
print (self.animal_tiger)

tmp = animal()
tmp.create('animal_tiger')


#

# Case 3: This does not work
indata = 'animal.tiger'
vars()[indata] = "Tigers, big and strong!"
print (animal.tiger)


#Case 4: This does not work
class animal():
def create (self, indata):
vars(self)[indata] = "Tigers, big and strong!"
print (self.animal.tiger)

tmp = animal()
tmp.create('animal.tiger')











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


Re: best way to remove leading zeros from a tuple like string

2018-05-20 Thread bruceg113355
On Sunday, May 20, 2018 at 6:56:05 PM UTC-4, Ben Bacarisse wrote:
> "Michael F. Stemper"  writes:
> 
> > On 2018-05-20 16:19, Ben Bacarisse wrote:
> >> bruceg113...@gmail.com writes:
> >>
> >>> Lets say I have the following tuple like string.
> >>>(128, 020, 008, 255)
> >>>
> >>> What is the best way to to remove leading zeroes and end up with the 
> >>> following.
> >>>(128, 20, 8, 255)-- I do not care about spaces
> >>
> >> You could use a regexp:
> >>
> >>import re
> >>...
> >>re.sub(r"(? >>
> >> I post this because I think it works (interesting corner cases are 10005
> >> and 000), 
> >
> > Seeing this makes me realize that mine will eliminate any numbers that
> > are all leading zero, including '0'. Also, forms like '-0042' will be
> > left unchanged.
> 
> I realised after posting the negatives won't work.  Not, I suspect, an
> issue for the OP but -0042 can certainly be said to have "leading
> zeros".
> 
> > Maybe splitting it into integer forms and sending each through
> > str( int( ) ) would be the safest.
> 
> Yup.  I gave a version of that method too which handles negative numbers
> by accident (by leaving the - in place!).  A better version would be
> 
>   re.sub(r"-?[0-9]+", lambda m: str(int(m.group(0))), s)
> 
> 
> -- 
> Ben.



Looking over the responses, I modified my original code as follows:

>>> s = "(128, 020, 008, 255, -1203,01,-000, -0123)" 
>>> ",".join([str(int(i)) for i in s[1:-1].split(",")])
'128,20,8,255,-1203,1,0,-123'


If I decide I need the parentheses, this works.

>>> "(" + ",".join([str(int(i)) for i in s[1:-1].split(",")]) + ")"
'(128,20,8,255,-1203,1,0,-123)'

Thanks,
Bruce

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

Re: best way to remove leading zeros from a tuple like string

2018-05-20 Thread bruceg113355
On Sunday, May 20, 2018 at 5:32:32 PM UTC-4, Paul wrote:
> >
> >
> > This works for me: mytuplestring.replace("0","")
> >
> > Your regex will also eliminate  non-leading zeros.


Your right, what was I thinking?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: best way to remove leading zeros from a tuple like string

2018-05-20 Thread bruceg113355
On Sunday, May 20, 2018 at 5:01:08 PM UTC-4, Michael F. Stemper wrote:
> On 2018-05-20 14:54, bruceg113...@gmail.com wrote:
> > Lets say I have the following tuple like string.
> >(128, 020, 008, 255)
> > 
> > What is the best way to to remove leading zeroes and end up with the 
> > following.
> >(128, 20, 8, 255)-- I do not care about spaces
> 
> 
> I'd use a few regular expressions:
> 
>  >>> from re import sub
>  >>> tuple = '(0128, 020, 008,012, 255)'
>  >>> sub( " 0*", " ", tuple ) # leading zeroes following space(s)
> '(0128, 20, 8,012, 255)'
>  >>> sub( ",0*", ",", tuple ) # leading zeroes following comma
> '(0128, 020, 008,12, 255)'
>  >>> sub( "\(0*", "(", tuple ) # leading zeroes after opening parend
> '(128, 020, 008,012, 255)'
> 
> Each step could be written as "tuple = sub( ..."
> 
>  >>> tuple = sub( " 0*", " ", tuple ) # following space(s)
>  >>> tuple = sub( ",0*", ",", tuple ) # following comma
>  >>> tuple = sub( "\(0*", "(", tuple ) # after opening parend
>  >>> tuple
> '(128, 20, 8,12, 255)'
>  >>>
> 
> 
> Or, if you like to make your code hard to read and maintain, you could
> combine them all into a single expression:
> 
>  >>> sub( " 0*", " ", sub( ",0*", ",", sub( "\(0*", "(", tuple ) ) )
> '(128, 20, 8,12, 255)'
>  >>>
> 
> -- 
> Michael F. Stemper
> What happens if you play John Cage's "4'33" at a slower tempo?



I did not think about using regular expressions.
After your response, I looked into regular expressions and also found  
Regex.Replace
After thinking about my question, I said why not use a replace statement.
This works for me: mytuplestring.replace("0","")

Thanks for a good starting point:)
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


best way to remove leading zeros from a tuple like string

2018-05-20 Thread bruceg113355
Lets say I have the following tuple like string.
  (128, 020, 008, 255)

What is the best way to to remove leading zeroes and end up with the following.
  (128, 20, 8, 255)-- I do not care about spaces

This is the solution I came up with
s = "(128, 020, 008, 255)"
v = s.replace ("(", "")
v = v.replace (")", "")
vv = ",".join([str(int(i)) for i in v.split(",")])
final = "(" + vv + ")"


Thanks,
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


Fastest way to remove the first x characters from a very long string

2015-05-16 Thread bruceg113355
I have a string that contains 10 million characters.

The string is formatted as:

001 : some hexadecimal text ... \n
002 : some hexadecimal text ... \n
003 : some hexadecimal text ... \n
...
010 : some hexadecimal text ... \n
011 : some hexadecimal text ... \n

and I need the string to look like:

some hexadecimal text ... \n
some hexadecimal text ... \n
some hexadecimal text ... \n
...
some hexadecimal text ... \n
some hexadecimal text ... \n

I can split the string at the : then iterate through the list removing the 
first 8 characters then convert back to a string. This method works, but it 
takes too long to execute.

Any tricks to remove the first n characters of each line in a string faster?

Thanks,
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to remove the first x characters from a very long string

2015-05-16 Thread bruceg113355
On Saturday, May 16, 2015 at 10:06:31 AM UTC-4, Stefan Ram wrote:
 bruceg113...@gmail.com writes:
 Your approach using .join is what I was looking for.
 
   I'd appreciate a report of your measurements.

# Original Approach
# -
ss = ss.split(\n)
ss1 = 
for sdata in ss:
ss1 = ss1 + (sdata[OFFSET:] + \n)


# Chris's Approach
# 
lines = ss.split(\n)
new_text = \n.join(line[8:] for line in lines)  


Test #1, Number of Characters: 165110
Original Approach: 18ms
Chris's Approach:   1ms

Test #2, Number of Characters: 470763
Original Approach: 593ms
Chris's Approach:   16ms

Test #3, Number of Characters: 944702
Original Approach: 2.824s
Chris's Approach:47ms

Test #4, Number of Characters: 5557394
Original Approach: 122s
Chris's Approach:   394ms
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to remove the first x characters from a very long string

2015-05-16 Thread bruceg113355
On Saturday, May 16, 2015 at 12:59:19 PM UTC-4, Chris Angelico wrote:
 On Sun, May 17, 2015 at 2:22 AM,  bruceg113...@gmail.com wrote:
  # Original Approach
  # -
  ss = ss.split(\n)
  ss1 = 
  for sdata in ss:
  ss1 = ss1 + (sdata[OFFSET:] + \n)
 
 
  # Chris's Approach
  # 
  lines = ss.split(\n)
  new_text = \n.join(line[8:] for line in lines)
 
 Ah, yep. This is exactly what str.join() exists for :) Though do make
 sure the results are the same for each - there are two noteworthy
 differences between these two. Your version has a customizable OFFSET,
 where mine is hard-coded; I'm sure you know how to change that part.
 The subtler one is that \n.join(...) won't put a \n after the final
 string - your version ends up adding one more newline. If that's
 important to you, you'll have to add one explicitly. (I suspect
 probably not, though; ss.split(\n) won't expect a final newline, so
 you'll get a blank entry in the list if there is one, and then you'll
 end up reinstating the newline when that blank gets joined in.) Just
 remember to check correctness before performance, and you should be
 safe.
 
 ChrisA

Hi Chris,

Your approach more than meets my requirements.
Data is formatted correctly and performance is simply amazing. 
OFFSET and \n are small details.

Thank you again,
Bruce

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


Re: Fastest way to remove the first x characters from a very long string

2015-05-16 Thread bruceg113355
On Saturday, May 16, 2015 at 9:46:17 AM UTC-4, Chris Angelico wrote:
 On Sat, May 16, 2015 at 11:28 PM,  bruceg113...@gmail.com wrote:
  I have a string that contains 10 million characters.
 
  The string is formatted as:
 
  001 : some hexadecimal text ... \n
  002 : some hexadecimal text ... \n
  003 : some hexadecimal text ... \n
  ...
  010 : some hexadecimal text ... \n
  011 : some hexadecimal text ... \n
 
  and I need the string to look like:
 
  some hexadecimal text ... \n
  some hexadecimal text ... \n
  some hexadecimal text ... \n
  ...
  some hexadecimal text ... \n
  some hexadecimal text ... \n
 
  I can split the string at the : then iterate through the list removing 
  the first 8 characters then convert back to a string. This method works, 
  but it takes too long to execute.
 
  Any tricks to remove the first n characters of each line in a string faster?
 
 Given that your definition is each line, what I'd advise is first
 splitting the string into lines, then changing each line, and then
 rejoining them into a single string.
 
 lines = original_text.split(\n)
 new_text = \n.join(line[8:] for line in lines)
 
 Would that work?
 
 ChrisA


Hi Chris,

I meant to say I can split the string at the \n.

Your approach using .join is what I was looking for.
Thank you,

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


Re: Fastest way to remove the first x characters from a very long string

2015-05-16 Thread bruceg113355
On Saturday, May 16, 2015 at 11:13:45 AM UTC-4, Rustom Mody wrote:
 On Saturday, May 16, 2015 at 8:30:02 PM UTC+5:30, Grant Edwards wrote:
  On 2015-05-16, bruceg113355 wrote:
  
   I have a string that contains 10 million characters.
  
   The string is formatted as:
  
   001 : some hexadecimal text ... \n
   002 : some hexadecimal text ... \n
   003 : some hexadecimal text ... \n
   ...
   010 : some hexadecimal text ... \n
   011 : some hexadecimal text ... \n
  
   and I need the string to look like:
  
   some hexadecimal text ... \n
   some hexadecimal text ... \n
   some hexadecimal text ... \n
   ...
   some hexadecimal text ... \n
   some hexadecimal text ... \n
  
   I can split the string at the : then iterate through the list
   removing the first 8 characters then convert back to a string. This
   method works, but it takes too long to execute.
  
   Any tricks to remove the first n characters of each line in a string 
   faster?
  
  Well, if the strings are all in a file, I'd probably just use sed:
  
  $ sed 's/^//g' file1.txt file2.txt
  
  or
  
  $ sed 's/^.*://g' file1.txt file2.txt
 
 
 And if they are not in a file you could start by putting them (it) there :-)
 
 Seriously... How does your 'string' come into existence?
 How/when do you get hold of it?

Data is coming from a wxPython TextCtrl widget.
The widget is displaying data received on a serial port for a user to analyze.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-16 Thread bruceg113355
On Thursday, November 15, 2012 11:16:08 PM UTC-5, Ethan Furman wrote:
 Emile van Sebille wrote:
 
 
  
 
  Using a decorator works when named arguments are not used. When named 
 
  arguments are used, unexpected keyword error is reported. Is there a 
 
  simple fix?
 
  
 
  Extend def wrapper(*args) to handle *kwargs as well
 
  
 
  Emile
 
  
 
  Code:
 
  -
 
 
 
  from functools import wraps
 
 
 
  def fix_args(fn):
 
  @wraps(fn)
 
  def wrapper(*args):
 
 so this line ^ becomes
 
 def wrapper(*args, **kwargs):
 
  args = (arg.replace('_', '') for arg in args)
 
 and add a line
 
 for k, v in kwargs:
 
 kwargs[k] = v.replace('_', '')
 
  return fn(*args)
 
 and this line ^ becomes
 
 return fn(*args, **kwargs)
 
  return wrapper
 
 
 
 ~Ethan~


Ethan,

I tried you code suggestions but got errors.
However, this works:

from functools import wraps

def fix_args(fn):
@wraps(fn)
def wrapper(*args, **kwargs): 
args = (arg.replace('_', '') for arg in args)
for kv in kwargs:
kwargs[kv] = kwargs[kv].replace('_', '') 
return fn(*args, **kwargs) 
return wrapper
   
@fix_args
def foo(a1=, a2=, b1=, b2=):
 print(a1)
 print(a2)
 print(b1)
 print(b2)
 print 
 

 
foo ('a1a1_x', 'a2a2_x', 'b1b1_x', 'b2b2_x')
foo (a1='a1a1_x', a2='a2a2_x', b1='b1b1_x', b2='b2b2_x') 
foo ('a1a1_x', 'a2a2_x', b1='b1b1_x', b2='b2b2_x') 

Bruce



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


Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-10 Thread bruceg113355
On Friday, November 9, 2012 8:16:12 PM UTC-5, Steven D'Aprano wrote:
 On Fri, 09 Nov 2012 20:05:26 -0500, Roy Smith wrote:
 
 
 
  In article 18134e77-9b02-4aec-afb0-794ed900d...@googlegroups.com,
 
   bruceg113...@gmail.com wrote:
 
  
 
  Is there a simpler way to modify all arguments in a function before
 
  using the arguments?
 
  
 
  For example, can the below code, in the modify arguments section be
 
  made into a few statements?
 
  
 
  def someComputation (aa, bb, cc, dd, ee, ff, gg, hh):
 
 # modify arguments
 
 # --
 
  aa = aa.replace (³_² , ³²)
 
  bb=  bb.replace (³_² , ³²)
 
  cc = cc.replace (³_² , ³²)
 
  dd = dd.replace (³_² , ³²)
 
  ee = ee.replace (³_² , ³²)
 
  ff = ff.replace (³_² , ³²)
 
  gg = gg.replace (³_² , ³²)
 
  hh = hh.replace (³_² , ³²)
 
  
 
 # use the arguments
 
 # -
 
 # Š
 
  
 
  You could do something like (not error checked)...
 
  
 
  def someComputation(*args):
 
  new_args = [arg.replace(_, ) for arg in args] aa, bb, cc, dd,
 
  ee, ff, gg, hh = new_args
 
  
 
  but that's pretty weird.  I suspect you just want to pass a list instead
 
  of a bunch of discrete arguments.
 
 
 
 
 
 I agree with everything you say except that it is pretty weird. As far as 
 
 I am concerned, it isn't weird at all.
 
 
 
 If you need named parameters:
 
 
 
 def someComputation(aa, bb, cc, dd, ee, ff, gg, hh):
 
 aa, bb, cc, dd, ee, ff, gg, hh = [arg.replace(_, ) 
 
 for arg in (aa. bb, cc, dd, ee, ff, gg, hh)]
 
 ...
 
 
 
 
 
 
 
 -- 
 
 Steven


Thanks to all. 
Steve's example is the one I will try next week. 
Passing in lists, will work but it requires extra coding from the calling 
routines to build the list.
Discrete arguments make sense. 
Also, what is the problem passing in 7 or more arguments?

Thanks,
Bruce
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-10 Thread bruceg113355
All,

I never used decorators before. I saw Miki Tebeka's sample code and your 
rationale (Aahz) and I like it. For my application problem, decorators seem 
like a good solution.

Thanks to all,
Bruce




On Saturday, November 10, 2012 10:35:12 AM UTC-5, Aahz wrote:
 In article mailman.3530.1352538537.27098.python-l...@python.org,
 
 Peter Otten  __pete...@web.de wrote:
 
 Miki Tebeka wrote:
 
 
 
  Is there a simpler way to modify all arguments in a function before using
 
  the arguments?
 
 
 
  You can use a decorator:
 
  
 
  from functools import wraps
 
  
 
  def fix_args(fn):
 
  @wraps(fn)
 
  def wrapper(*args):
 
  args = (arg.replace('_', '') for arg in args)
 
  return fn(*args)
 
  
 
  return wrapper
 
  
 
  @fix_args
 
  def foo(x, y):
 
  print(x)
 
  print(y)
 
 
 
 I was tempted to post that myself, but he said /simpler/ ;)
 
 
 
 From my POV, that *is* simpler.  When you change the parameters for foo,
 
 you don't need to change the arg pre-processing.  Also allows code reuse,
 
 probably any program needing this kind of processing once will need it
 
 again.
 
 -- 
 
 Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/
 
 
 
 Normal is what cuts off your sixth finger and your tail...  --Siobhan

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


Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-09 Thread bruceg113355
Is there a simpler way to modify all arguments in a function before using the 
arguments?

For example, can the below code, in the modify arguments section be made into a 
few statements?  

def someComputation (aa, bb, cc, dd, ee, ff, gg, hh):
   # modify arguments
   # --
aa = aa.replace (“_” , “”)
bb=  bb.replace (“_” , “”)
cc = cc.replace (“_” , “”)
dd = dd.replace (“_” , “”)
ee = ee.replace (“_” , “”)
ff = ff.replace (“_” , “”)
gg = gg.replace (“_” , “”) 
hh = hh.replace (“_” , “”)

   # use the arguments
   # -
   # …

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


Need to archive a MySQL database using a python script

2012-09-25 Thread bruceg113355
Python Users Group,

I need to archive a MySQL database using a python script.
I found a good example at: https://gist.github.com/3175221

The following line executes however, the archive file is empty.

os.popen(mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c  %s.gz %
   (user,password,host,database,database+_+filestamp))
Where:
  User = “someUser”
  password = “somePassword”
  host = “someRemote.database.server”
  database = “someDatabase”

If I execute mysqldump from the command line, an archive is created.

Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb)
Mysql-5.5.27 from the command line.

Any ideas?

Thanks,
Bruce
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 and Sqlite3 - Slow

2012-08-28 Thread bruceg113355
On Tuesday, August 28, 2012 4:27:48 AM UTC-4, Cameron Simpson wrote:
 On 27Aug2012 13:41, bruceg113...@gmail.com bruceg113...@gmail.com wrote:
 
 | When using the database on my C Drive, Sqlite performance is great!   (1S)
 
 | When using the database on a network, Sqlite performance is terrible! (17S)
 
 
 
 Let me first echo everyone saying not to use SQLite on a network file.
 
 
 
 | I like your idea of trying Python 2.7
 
 
 
 I doubt it will change anything.
 
 
 
 | Finally, the way my program is written is:
 
 |   loop for all database records:
 
 |  read a database record
 
 |  process data
 
 |  display data (via wxPython)
 
 | 
 
 | Perhaps, this is a better approach:
 
 |  read all database records
 
 |  loop for all records:
 
 | process data
 
 | display data (via wxPython)
 
 
 
 Yes, provided the read all database records is a single select
 
 statement. In general, with any kind of remote resource you want to
 
 minimise the number of transactions - the to and fro part, because each
 
 such item tends to have latency while something is sent to and again
 
 receiving from. So if you can say gimme all the records you get one
 
 unit of latency at the start and end, versus latency around each
 
 record fetch.
 
 
 
 Having said all that, because SQLite works directly against the file, if
 
 you say to it giev me all the records and the file is remote, SQLite
 
 will probably _still_ fetch each record individually internally, gaining
 
 you little.
 
 
 
 This is why people are suggesting a database server: then you can say
 
 get me all the records over the net, and the server does
 
 local-to-the-server file access to obtain the data. So all the per
 
 record latency is at its end, and very small. Not to mention any
 
 cacheing it may do.
 
 
 
 Of course, if your requirements are very simple you might be better off
 
 with a flat text file, possibly in CSV format, and avoid SQLite
 
 altogether.
 
 
 
 Cheers,
 
 -- 
 
 Cameron Simpson c...@zip.com.au
 
 
 
 I do not trust thee, Cage from Hell, / The reason why I cannot tell, /
 
 But this I know, and know full well: / I do not trust thee, Cage from Hell.
 
 - Leigh Ann Hussey, leigh...@sybase.com, DoD#5913



Cameron,

I did some testing and approach #1 is significantly faster than approach #2:
Approach #1:
  read all database records
  loop for all records:
 process data
 display data (via wxPython) 

Approach #2:
   loop for all database records:
  read a database record
  process data
  display data (via wxPython)

Various test results to read 50 records from a network drive. 
  #1  0:00:00.078000 
  #2  0:00:04.219000

  #1  0:00:00.875000
  #2  0:00:08.031000

  #1  0:00:00.063000
  #2  0:00:06.109000

  #1  0:00:00.078000
  #2  0:00:05.11

  #1  0:00:00.156000
  #2  0:00:02.625000

This explains some of my slowness issues.

Note: When the network drive is behaving (not slow), approach #2 is close to 
approach #1.


From the site: http://www.sqlite.org/different.html
--
Most SQL database engines are implemented as a separate server process. 
Programs that want to access the database communicate with the server using 
some kind of interprocess communication (typically TCP/IP) to send requests to 
the server and to receive back results. SQLite does not work this way. With 
SQLite, the process that wants to access the database reads and writes directly 
from the database files on disk. There is no intermediary server process.

There are advantages and disadvantages to being serverless. The main 
advantage is that there is no separate server process to install, setup, 
configure, initialize, manage, and troubleshoot. This is one reason why SQLite 
is a zero-configuration database engine. Programs that use SQLite require no 
administrative support for setting up the database engine before they are run. 
Any program that is able to access the disk is able to use an SQLite database.

On the other hand, a database engine that uses a server can provide better 
protection from bugs in the client application - stray pointers in a client 
cannot corrupt memory on the server. And because a server is a single 
persistent process, it is able control database access with more precision, 
allowing for finer grain locking and better concurrency.

Most SQL database engines are client/server based. Of those that are 
serverless, SQLite is the only one that this author knows of that allows 
multiple applications to access the same database at the same time. 
--


Doesn't the last paragraph imply that SQLite can operate on a network drive.

Thanks,
Bruce 

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


Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread bruceg113355
Uli,

Answers to your questions:
1) There are approx 65 records and each record is 68 bytes in length.
2) Not applicable because number of records is fixed.
3) Takes less than a second to read all 65 records when all is well.
   Takes 17 seconds to read all 65 records when all is NOT WELL
4) Performance is also sluggish, at least 12 seconds.
5) Most likely, I misspoken. Restarting my program does not always help with 
performance.

When using the database on my C Drive, Sqlite performance is great!   (1S)
When using the database on a network, Sqlite performance is terrible! (17S)

I like your idea of trying Python 2.7

Finally, the way my program is written is:
  loop for all database records:
 read a database record
 process data
 display data (via wxPython)

Perhaps, this is a better approach:
 read all database records
 loop for all records:
process data
display data (via wxPython)

Thanks,
Bruce





On Monday, August 27, 2012 11:50:15 AM UTC-4, Ulrich Eckhardt wrote:
 Am 27.08.2012 03:23, schrieb bruceg113...@gmail.com:
 
  My program uses Python 2.6 and Sqlite3 and connects to a network
 
  database 100 miles away.
 
 
 
 Wait, isn't SQLite completely file-based? In that case, SQLite accesses
 
 a file, which in turn is stored on a remote filesystem. This means that 
 
 there are other components involved here, namely your OS, the network 
 
 (bandwidth  latency), the network filesystem and the filesystem on the 
 
 remote machine. It would help if you told us what you have there.
 
 
 
 
 
  My program reads approx 60 records (4000 bytes) from a Sqlite
 
  database in less than a second. Each time the user requests data, my
 
  program can continuously read 60 records in less than a second.
 
  However, if I access the network drive  (e.g. DOS command DIR /S)
 
  while my program is running, my program takes 20 seconds to read the
 
  same 60 records. If I restart my program, my program once again takes
 
  less than a second to read 60 records.
 
 
 
 Questions here:
 
 1. Is each record 4kB or are all 60 records together 4kB?
 
 2. Does the time for reading double when you double the number of 
 
 records? Typically you have B + C * N, but it would be interesting to 
 
 know the bias B and the actual time (and size) of each record.
 
 3. How does the timing change when running dir/s?
 
 4. What if you run two instances of your program?
 
 5. Is the duration is only reset by restarting the program or does it 
 
 also decrease when the dir/s call has finished? What if you close and 
 
 reopen the database without terminating the program?
 
 
 
 My guess is that the concurrent access by another program causes the 
 
 accesses to become synchronized, while before most of the data is 
 
 cached. That would cause a complete roundtrip between the two machines 
 
 for every access, which can easily blow up the timing via the latency.
 
 
 
 In any case, I would try Python 2.7 in case this is a bug that was 
 
 already fixed.
 
 
 
 Good luck!
 
 
 
 Uli

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


Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread bruceg113355
Demian,

I am not a database expert!
I selected sqlite for the following reasons:

1) Ships with Python.
2) Familiar with Python.
3) The Sqlite description at http://www.sqlite.org/whentouse.html appears to 
meet my requirements:
Very low volume and concurrency, small datasets, simple to use.

Bruce
 

On Monday, August 27, 2012 4:54:07 PM UTC-4, Demian Brecht wrote:
 Is there a reason that you're using SQLite in a network environment rather 
 than a database server?

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


Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread bruceg113355
On Monday, August 27, 2012 10:32:47 PM UTC-4, Bryan wrote:
 bruceg113 wrote:
 
  I selected sqlite for the following reasons:
 
 
 
  1) Ships with Python.
 
  2) Familiar with Python.
 
  3) The Sqlite description athttp://www.sqlite.org/whentouse.htmlappears to 
  meet my requirements:
 
      Very low volume and concurrency, small datasets, simple to use.
 
 
 
 All good reasons, but a database file on a network drive is
 
 contraindication for SQLite. A Google site-specific search
 
 for network on www.sqlite.org, finds such warnings as:
 
 
 
 We have received reports of implementations of both Windows network
 
 filesystems and NFS in which locking was subtly broken. We can not
 
 verify these reports, but as locking is difficult to get right on a
 
 network filesystem we have no reason to doubt them. You are advised to
 
 avoid using SQLite on a network filesystem in the first place, since
 
 performance will be slow.
 
 
 
 That said, I don't know where your 17 seconds is going.
 
 
 
 -Bryan

Bryan,

Thank you for your reply. 
Are you saying having a sqlite database file on a shared LOCAL network drive is 
problematic? 

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


Python 2.6 and Sqlite3 - Slow

2012-08-26 Thread bruceg113355

My program uses Python 2.6 and Sqlite3 and connects to a network database 100 
miles away. 
My program reads approx 60 records (4000 bytes) from a Sqlite database in less 
than a second. 
Each time the user requests data, my program can continuously read 60 records 
in less than a second. 
However, if I access the network drive  (e.g.  DOS command DIR /S)  while my 
program is running, my program takes 20 seconds to read the same 60 records. If 
I restart my program, my program once again takes less than a second to read 60 
records.

Any ideas?

Thanks,
Bruce
-- 
http://mail.python.org/mailman/listinfo/python-list


Is there a clever way to pass arguments

2012-08-08 Thread bruceg113355
Is there a way in Python to pass arguments without listing each argument?
For example, my program does the following:

testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7])

Is there a clever way to pass arguments in a single statement knowing that each 
argument is a sequential index from a list?
I cannot change the function definition.

Thanks,
Bruce
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a clever way to pass arguments

2012-08-08 Thread bruceg113355
On Wednesday, August 8, 2012 9:07:04 PM UTC-4, Dave Angel wrote:
 On 08/08/2012 08:41 PM, bruceg113...@gmail.com wrote:
 
  Is there a way in Python to pass arguments without listing each argument?
 
  For example, my program does the following:
 
 
 
  testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7])
 
 
 
  Is there a clever way to pass arguments in a single statement knowing that 
  each argument is a sequential index from a list?
 
  I cannot change the function definition.
 
 
 
  Thanks,
 
  Bruce
 
 If a function is expecting exactly 8 arguments, and z is a list of
 
 length 8, you can call the function like:
 
 
 
  testData(*z)
 
 
 
 if z is longer, then you'd need something like (untested)
 
 testData(*z[:8])
 
 
 
 The * basically turns a list into separate arguments, and these are then
 
 applied to the formal parameters.
 
 
 
 -- 
 
 
 
 DaveA








Dave, your solution works!

def testData (z0, z1, z2, z3, z4, z5, z6, z7):
print (z0, z1, z2, z3, z4, z5, z6, z7)

z = []
z.append(0)
z.append(1)
z.append(2)
z.append(3)
z.append(4)
z.append(5)
z.append(6)
z.append(7)

testData(*z[:8])

Thank you,
Bruce
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and Outlook, sendinf an image in the body of email

2012-07-23 Thread bruceg113355
All,

I am trying to figure out how to send a image in the body of a email when 
Making a Meeting Request.
Below is my current code.

Thanks,
Bruce


# code below is mainly from 
http://harunprasad.blogspot.com/2012/01/python-make-meeting-request-appointment.html
# 
--

import win32com.client
oOutlook = win32com.client.Dispatch(Outlook.Application)
appt = oOutlook.CreateItem(1) 
appt.Start = '2012-07-24 08:00'
appt.Subject = '5th Meeting'
appt.Duration = 60
appt.Location = 'Conference Room, Main'


appt.Body = This is body text\n
attach1 = someimage.jpg
appt.Attachments.Add (attach1)#prefer to have attachment inline (body) 
of email

appt.MeetingStatus = 1 

appt.Recipients.Add(some...@email.com) #enter valid email here

appt.Save()
appt.Send()

print Done


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


Re: Python and Outlook, sendinf an image in the body of email

2012-07-23 Thread bruceg113355
These do not work:

  appt.BodyFormat = olBodyFormat.olFormatHTML 
  ...
  appt.BodyFormat = olBodyFormat.olFormatHTML
  NameError: name 'olBodyFormat' is not defined

  

  appt.BodyFormat = win32com.client.constants.olFormatHTML 
 ...
 appt.BodyFormat = win32com.client.constants.olFormatHTML
 File C:\Python26\lib\site-packages\win32com\client\__init__.py, 
line 170, in  __getattr__
 raise AttributeError(a)
 AttributeError: olFormatHTML


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


Re: Python and Outlook, sendinf an image in the body of email

2012-07-23 Thread bruceg113355

This assignment works:
  import win32com.client
  oOutlook = win32com.client.Dispatch(Outlook.Application)
  appt = oOutlook.CreateItem(0)
  appt.BodyFormat = win32com.client.constants.olFormatHTML 

But this assignment does not work:
  import win32com.client
  oOutlook = win32com.client.Dispatch(Outlook.Application
  appt = oOutlook.CreateItem(1)  #appointment
  appt.BodyFormat = win32com.client.constants.olFormatHTML 

  AttributeError: ... object has no attribute 'BodyFormat'

It simply appears an Appointment Item does not support .BodyFormat
Images are delivered as attachments, can not be in the body (inline) of the 
appointment email.


Bruce




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