Re: Dabbling in web development

2015-11-20 Thread bSneddon
Thanks all!
-- 
https://mail.python.org/mailman/listinfo/python-list


Dabbling in web development

2015-11-19 Thread bSneddon
I know there are a plethora of web frameworks out there for Python and to be 
serious about website developement I should learn on like Django.   Really 
thought, I just want to dabble and do some easy stuff.   Does anyone have any 
suggestons?   I have a a website hosted with a hosting company who is supposed 
to have python support but hard to know what they have installed on there 
apache server.   I have seen a few examples out there but not too many.  
-- 
https://mail.python.org/mailman/listinfo/python-list


When do default parameters get their values set?

2014-12-09 Thread bSneddon
I ran into an issue setting variables from a GUI module that imports a back end 
module.  My approach was wrong obviously but what is the best way to set values 
in a back end module.

#module name beTest.py

cfg = { 'def' : 'blue'}

def printDef(argT = cfg['def']):
print argT


#module name feTest
import beTest

beTest.cfg['def'] = "no red"
beTest.printDef()



This prints blue.  I suppose because I am changing a local copy of cfg 
dictionary.  What is the write approach here?


Thanks

Bill

--- SoupGate-Win32 v1.05
 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999)
--- Synchronet 3.15b-Win32 NewsLink 1.92
SpaceSST BBS Usenet <> Fidonet Gateway
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When do default parameters get their values set?

2014-12-08 Thread bSneddon
Thanks to all.  I now understand what is happening.   Originally wrote a script 
 be executed from command line.   No want to use Gui to change defaults.   Will 
refactor to fix where necessary.

On Monday, December 8, 2014 5:10:58 PM UTC-5, bSneddon wrote:
> I ran into an issue setting variables from a GUI module that imports a back 
> end module.  My approach was wrong obviously but what is the best way to set 
> values in a back end module.
> 
> #module name beTest.py
> 
> cfg = { 'def' : 'blue'}
> 
> def printDef(argT = cfg['def']):
>   print argT
>  
> 
> #module name feTest
> import beTest
> 
> beTest.cfg['def'] = "no red"
> beTest.printDef()
> 
> 
> 
> This prints blue.  I suppose because I am changing a local copy of cfg 
> dictionary.  What is the write approach here?
> 
> 
> Thanks
> 
> Bill
-- 
https://mail.python.org/mailman/listinfo/python-list


When do default parameters get their values set?

2014-12-08 Thread bSneddon
I ran into an issue setting variables from a GUI module that imports a back end 
module.  My approach was wrong obviously but what is the best way to set values 
in a back end module.

#module name beTest.py

cfg = { 'def' : 'blue'}

def printDef(argT = cfg['def']):
print argT
 

#module name feTest
import beTest

beTest.cfg['def'] = "no red"
beTest.printDef()



This prints blue.  I suppose because I am changing a local copy of cfg 
dictionary.  What is the write approach here?


Thanks

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


Re: Creating a 2s compliment hex string for negitive numbers

2014-08-01 Thread bSneddon
On Friday, August 1, 2014 4:47:20 PM UTC-4, MRAB wrote:
> On 2014-08-01 21:35, bSneddon wrote:
> 
> > I need to calculate an error correction code for an old protocol.
> 
> >
> 
> > I calculate the integer 4617 and want to code the 2s compliment in ASCII
> 
> > hex EDF7.  When issue the following.
> 
> >>>> hex(-4617)
> 
> > '-0x1209'
> 
> >
> 
> > Does anyone know a clean way to get to the desired results?   My ECC will 
> > always
> 
> > be 16 bit (4 nibble) hex number.
> 
> >
> 
> Use a bitwise AND:
> 
> 
> 
>  >>> hex(-4617 & 0x)
> 
> '0xedf7'

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


Creating a 2s compliment hex string for negitive numbers

2014-08-01 Thread bSneddon
I need to calculate an error correction code for an old protocol.

I calculate the integer 4617 and want to code the 2s compliment in ASCII
hex EDF7.  When issue the following.
>>> hex(-4617)
'-0x1209'   

Does anyone know a clean way to get to the desired results?   My ECC will always
be 16 bit (4 nibble) hex number.

Bill

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


Re: parse a string of parameters and values

2009-12-13 Thread bsneddon
On Dec 13, 5:28 am, Peter Otten <__pete...@web.de> wrote:
> bsneddon wrote:
> > I have a problem that I can come up with a brute force solution to
> > solve but it occurred to me that there may be an
> >  "one-- and preferably only one --obvious way to do it".
>
> > I am going to read a text file that is an export from a control
> > system.
> > It has lines with information like
>
> > base=1 name="first one" color=blue
>
> > I would like to put this info into a dictionary for processing.
> > I have looked at optparse and getopt maybe they are the answer but
> > there could
> > be and very straight forward way to do this task.
>
> > Thanks for your help
>
> Have a look at shlex:
>
> >>> import shlex
> >>> s = 'base=1 name="first one" color=blue equal="alpha=beta" empty'
> >>> dict(t.partition("=")[::2] for t in shlex.split(s))
>
> {'color': 'blue', 'base': '1', 'name': 'first one', 'empty': '', 'equal':
> 'alpha=beta'}
>
> Peter

Thanks to all for your input.

It seems I miss stated the problem.  Text is always quoted so blue
above -> "blue".

Peter,

The part I was missing was t.partition("=") and slicing skipping by
two.
It looks like a normal split will work for me to get the arguments I
need.
To my way of thinking your is very clean any maybe the "--obvious way
to do it"
Although it was not obvious to me until seeing your post.

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


parse a string of parameters and values

2009-12-12 Thread bsneddon
I have a problem that I can come up with a brute force solution to
solve but it occurred to me that there may be an
 "one-- and preferably only one --obvious way to do it".

I am going to read a text file that is an export from a control
system.
It has lines with information like

base=1 name="first one" color=blue

I would like to put this info into a dictionary for processing.
I have looked at optparse and getopt maybe they are the answer but
there could
be and very straight forward way to do this task.

Thanks for your help
-- 
http://mail.python.org/mailman/listinfo/python-list


Cashing in PythonWin name space?... seems unexpected to me

2009-10-08 Thread bsneddon
I saw an issue  on winXP  box not connected to internet yesterday,
where i was running
a script in the interactive window on PythonWin .   I would modify the
script save and
import and was still running the old version.  I did that several
times with same result.
I even renamed the function and it showed up but ran the old script.
Very strange.

I tried reproducing this morning on a machine that is connected to
internet was unable to
but did get the behavior below that I do not understand.

created module named spam with this code.
def ello():
print "Your father smells of elderberrys"

Here is expert for interactive window to explain the issue: question
is below.

PythonWin 2.6 (r26:66721, Oct  2 2008, 11:35:03)
I


renamed ello to insult and re-imported.

>>> dir(spam)
[clip.. 'ello', 'insult']

ello still exist in namespace an runs ... not so strange
>>> spam.ello()
Your father smells of elderberrys

>>> del(spam)
delete spam and it no longer runs as expected.

modify insult to this:
def insult():
print "Your father smells of elderberrys/n and your mother was a
kiniggit"

Q.
on re-importing spam ello is back and continues to run.   I did note
expect this to be the
case.  Can someone explain what is happening?

>>> dir(spam)
[clip..., 'ello', 'insult']
>>> spam.ello()
Your father smells of elderberrys
>>> spam.insult()
Your father smells of elderberrys/n and your mother was a kiniggit
>>>


Thanks for your help.

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


Re: problem of converting a list to dict

2008-01-09 Thread bsneddon
On Jan 9, 3:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > mylist=['','tom=boss','mike=manager','paul=employee','meaningless']
>
> > I'd like to remove the first and the last item as they are irrevalent,
> > and convert it to the dict:
> > {'tom':'boss','mike':'manager','paul':'employee'}
>
> > I tried this but it didn't work:
>
> > mydict={}
> > for i in mylist[1:-1]:
> >a=i.split('=')  # this will disect each item of mylist into a 
> > 2-item
> > list
> >mydict[a[0]]=a[1]
>
> > and I got this:
> >   File "srch", line 19, in 
> > grab("a/tags1")
> >   File "srch", line 15, in grab
> > mydict[mylist[0]]=mylist[1]
> > IndexError: list index out of range
>
> This can be rewritten a little more safely like
>
>mydict = dict(pair.split('=',1)
>  for pair in mylist
>  if '=' in pair)
>
> Some of John Machin's caveats still apply:
> (2) a[0] is empty or not what you expect (a person's name)
> (3) a[1] is empty or not what you expect (a job title)
> (consider what happens with 'tom = boss' ... a[0] = 'tom ', a[1] = '
> boss')
> (4) duplicate keys [, 'tom=boss', 'tom=clerk', ...]
>
> to which I'd add
>
> (5) what happens if you have more than one equals-sign in your
> item?  ("bob=robert=manager" or "bob=manager=big-cheese")
>
> #2 and #3 can be ameliorated a bit by
>
>import string
>mydict = dict(
>  map(string.strip,pair.split('=',1))
>  for pair in mylist
>  if '=' in pair)
>
> which at least whacks whitespace off either end of your keys and
> values.  #4 and #5 require a clearer definition of the problem.
>
> -tkc

This seemed to work for me if you are using 2.4 or greater and
like list comprehension.
>>> dict([ tuple(a.split("=")) for a in mylist[1:-1]])
{'mike': 'manager', 'paul': 'employee', 'tom': 'boss'}

should be faster than looping
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to convert a byte of integer into a list

2007-07-12 Thread bsneddon
On Jul 12, 8:49 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jul 13, 10:28 am, Paul Rubin  wrote:
>
> > Godzilla <[EMAIL PROTECTED]> writes:
> > > > num = 255
> > > > numlist = [num >> i & 1 for i in range(8)]
>
> > > Thanks matimus! I will look into it...
>
> > numlist = lookup_table[num]
>
> > where lookup_table is a precomputed list of lists.
>
> Ummm ... didn't the OP say he had 32-bit numbers???

List comprehension would be faster, lookup would be even faster but
would have to generate list or dictionary ahead of time
but this will work on any length int up 2 limit of int does not pad
with zeros on most significant end to word length.


n=input()
l=[]
while(n>0):
 l.append(str(n&1)); n=n>>1

I posted this here http://www.uselesspython.com/download.php?script_id=222
a while back.

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


Re: Pretty Printing Like Tidy for HTML

2007-07-08 Thread bsneddon
On Jul 8, 1:53 pm, bsneddon <[EMAIL PROTECTED]> wrote:
> On Jul 8, 10:59 am, [EMAIL PROTECTED] (John J. Lee) wrote:
>
>
>
> > David <[EMAIL PROTECTED]> writes:
> > > Is there a pretty printing utility for Python, something like Tidy for
> > > HTML?
>
> > > That will change:
>
> > > xp=self.uleft[0]+percentx*(self.xwidth)
>
> > > To:
>
> > > xp = self.uleft[0] + percentx * (self.xwidth)
>
> > > And other formatting issues.
>
> > Googled and found these; no idea if they're any good (latter is
> > commercial):
>
> >http://cheeseshop.python.org/pypi/PythonTidy/1.11
>
> >http://python.softalizer.com/
>
> > See also:
>
> >http://svn.python.org/view/python/trunk/Tools/scripts/reindent.py?vie...
>
> > John
>
> I did this useing the BeautifulSoup module.
> Used it on XML created by msWord which had no formating was
> all on one line.
>
> >>> import BeautifulSoup
> >>> soupStr = open('c:/data/quotes.xml').read()
> >>> soup = BeautifulSoup.BeautifulSoup(soupStr)
> >>> pSoup = soup.prettify()
> >>> outFile = open('c:/data/quotesTidy.xml','w')
> >>> outFile.write(pSoup)
> >>> outFile.close()

Sorry, I answered the wrong question.
You wanted to format code not HTML.

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


Re: Pretty Printing Like Tidy for HTML

2007-07-08 Thread bsneddon
On Jul 8, 10:59 am, [EMAIL PROTECTED] (John J. Lee) wrote:
> David <[EMAIL PROTECTED]> writes:
> > Is there a pretty printing utility for Python, something like Tidy for
> > HTML?
>
> > That will change:
>
> > xp=self.uleft[0]+percentx*(self.xwidth)
>
> > To:
>
> > xp = self.uleft[0] + percentx * (self.xwidth)
>
> > And other formatting issues.
>
> Googled and found these; no idea if they're any good (latter is
> commercial):
>
> http://cheeseshop.python.org/pypi/PythonTidy/1.11
>
> http://python.softalizer.com/
>
> See also:
>
> http://svn.python.org/view/python/trunk/Tools/scripts/reindent.py?vie...
>
> John

I did this useing the BeautifulSoup module.
Used it on XML created by msWord which had no formating was
all on one line.

>>> import BeautifulSoup
>>> soupStr = open('c:/data/quotes.xml').read()
>>> soup = BeautifulSoup.BeautifulSoup(soupStr)
>>> pSoup = soup.prettify()
>>> outFile = open('c:/data/quotesTidy.xml','w')
>>> outFile.write(pSoup)
>>> outFile.close()

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


Re: Validating XML in Windows

2007-07-08 Thread bsneddon
On Jul 8, 12:22 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Omari Norman wrote:
> > My app needs to validate XML. That's easy enough in Unix. What is the
> > best way to do it in Windows?
>
> > The most obvious choice would of course be PyXML. However, apparently it
> > is no longer maintained:
>
> >http://sourceforge.net/project/showfiles.php?group_id=6473
>
> > so there are no Windows binaries that work with Python 2.5. Getting
> > other XML libraries like libxml2 also seems to be quite difficult on
> > Windows.
>
> > Has anyone else dealt with this problem and found a solution? It would
> > even be fine if I could find a free command-line validator that I could
> > invoke with subprocess, but I haven't even had luck with that.
>
> lxml has statically built  Windows binaries available for version 1.2.1, those
> for 1.3.2 should become available soon. It supports RelaxNG, XMLSchema, DTDs
> and (with a little patching) Schematron.
>
> http://codespeak.net/lxml/
>
> Stefan

You might try something like this.  I am sure you can find help on
MSDN.
I know DOM may not be most efficient but could be a way to solve the
problem
on windows.
>>> import win32com.client
>>>
>>> import win32com.client
>>> objXML = win32com.client.Dispatch("MSXML2.DOMDocument.3.0")
>>> objXML.load(r'C:\data\pyexamples\xml\acro.xml')
True
# not sure how to load schema but there must be away
>>> objXML.validate()

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


XQuery module for Python

2007-07-05 Thread bsneddon
Does anyone know of a module for Python XML that includes XQuery?
http://www.w3.org/XML/Query/
It seem like it would be very useful.  Is there a down side to XQuery
that has prevented
it from being incorporated into some of the Python XML offerings?
I have googled this some and have not seen answer to my above
questions.

Bill

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