Read active tab URL from a browser with Python ?

2013-07-02 Thread goldtech
Hi,

I've goggled this but haven't found a way (at least a way I understand) for a 
running Python script to get the current URL in a browser's location bar. Is 
there a way? I'm using Windows so maybe that would provide a way (or not).

This isn't for a browser controlled/automated by Python that Pyhton might have 
a "hook" in, but just a "typical" running browser FF, IE...

Any help appreciated.

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


How to tell Script to use pythonw.exe ?

2013-07-02 Thread goldtech
Hi,

Using Windows

I want to run a .py file script using pythonw.exe so the DOS box will not open. 
Is there a way from inside the script to say "run me with pythonw.exe and not 
python.exe"?

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


Re: How to tell Script to use pythonw.exe ?

2013-07-02 Thread goldtech
I just changed the file extension of the script file from .py to .pyw and it 
uses pythonw.exe. I didn't read it anywhere, just intuited it and tried it. 
Python has some very smart people working the language...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read active tab URL from a browser with Python ?

2013-07-03 Thread goldtech
snip
> 
> Another option might be to use Python in conjuction with AutoIt:
> 
> 
> 
> http://www.pha.com.au/kb/index.php/Using_AutoIT_with_Python
> 
> http://www.autoitscript.com/forum/topic/115293-how-to-get-firefox-current-page-address/

This is powerful, and seems like I can call Autoit from Python. Thanks for 
turning me on to this!
-- 
http://mail.python.org/mailman/listinfo/python-list


How to read Mozrepl Javascript result into a Python Variable?

2013-07-13 Thread goldtech
Hi,

With Mozrepl addon in Firefox and Python I do:

>>> import telnetlib
>>> tn = telnetlib.Telnet(r'127.0.0.1', 4242, 5)
>>> tn.read_eager()
'\nWelcome to MozRepl.\n\n - If you get stuck at the "'
>>> tn.read_until("repl> ")
...snip...
>>> tn.write(r'alert(window.content.location.href)'+"\n")

and I get an alert box with the URL of the active tab. 

But how do I read that URL into a python variable? Something like 
tn.write(r';var zz = window.content.location.href'+ "\n") but that doesn't get 
it into python. 

I would be grateful for help. Thanks.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Help understanding an Object Oriented Program example

2012-10-28 Thread goldtech
Hi,

Trying to learn Python OOP. An example from a book, may not be
formated after sending post but:

class Contact:
all_contacts = []
def __init__(self, name, email):
self.name = name
self.email = email
Contact.all_contacts.append(self)

OK, no I do this:

>>> c = Contact('aaa','bbb')
>>> c = Contact('ccc','ddd')
>>> c = Contact('eee','fff')
>>> for i in Contact.all_contacts:
print i.name + '  ' + i.email


aaa  bbb
ccc  ddd
eee  fff
>>>
>>> c.name
'eee'

So wouldn't be good to add a check that the var (in this case c) does
not point to any object before creating an object to keep the list
correct?

Also all_contacts is a class variable. I think the author is hinting
that this would be a good idea for a contact list, But I don't fully
see the usage of it. How would each object use a class variable like
this? What would be the dot notation?

I realize this is a code fragment and is no way implementable code.
Any help appreciated. BTW, it's from "Python3 Object Oriented
Programming..." by D. Philips - very clearly written and enjoying
it...Thanks



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


How to install libxml2-devel and libxslt-devel in Windows ?

2012-11-10 Thread goldtech
Hi,

I have Windows XP and Python 2.7.x

I download and install libxml2-python-2.7.7.win32-py2.7.exe, From
here: http://users.skynet.be/sbi/libxml-python/

This file has both libxml2 AND libxslt.

But, I also need libxml2-devel and libxslt-devel for python 2.7. Are
binaries for win32 available for that?

How do I to get these devel files? In Ubuntu fro example this is all
in the repositories. But I guess I don't understand how to get this in
Windows...

Thank you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Script Works Locally But Not Remotely with SSH

2012-04-02 Thread goldtech
Hi,

I have a WinXP PC running an SSH server and I have a Linux PC with an
SSH client  and logged into the XP seemingly OK. It's all on my
personal LAN, the connection seems OK.

I have a py file on the XP that I run via SSH from the Linux, it's:

import webbrowser
webbrowser.open('www.google.com')

This runs OK started on the local XP PC, the browser Firefox opens and
goes to the site, or it opens a tab to the site. But executing that
same file via SSH does not open Firefox...doing it via SSH starts
Firefox ( I see it begin in the process manager and I see web
activity) but Firefox does not open it's window.

Why the does the window not open when the script is started remotely?

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


Re: Python Script Works Locally But Not Remotely with SSH

2012-04-02 Thread goldtech
Bump(?)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Works Locally But Not Remotely with SSH

2012-04-07 Thread goldtech
Thank you for the help.

I guess I didn't understand what's really going on. I thought if I SSH
even from a Linux to a Windows machine whatever I say on the SSH
client command line would be the same as me doing a command on the
"DOS" command-line in Windows. I incorrectly thought SSH is just a
tunnel for text...

But that's not what's going on, there's  a lot more to it. Thanks, I
will get into it more to understand this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Strings show as brackets with a 'u'.

2011-07-23 Thread goldtech

Hi,

>>> n
[u'174']
>>>

Probably newbie question but not sure how suppress the brackets and
the 'u' ? I assume pyhon is telling me it's a unicode string in the n
variable.

 I'm using using Idle on winXP, activestate 2.7. Is there a way to
suppress this and just show 174  in the shell ?
A script reading data and assigns 174 to n via some regex. Links on
this appreciated - I've tried to understand unicode before, will keep
trying...thanks.


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


Re: Strings show as brackets with a 'u'.

2011-07-26 Thread goldtech
Thank you. So what is happening? Is it that I'm in an environment that
is not unicode and python is telling me the string (ie. n[0]) is
unicode? (I'll do a hatchet-job on this subject if I ask anymore about
unicode). Thanks to posters for their patience!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings show as brackets with a 'u'.

2011-07-27 Thread goldtech

> Rick gave you some good advice, perhaps worth re-reading. What you need
> are investigative skills, and not just bits of data.


Totally agree. beginning to see what's going on. I'm not specifically
accessing the list element with n (vs. n[0]). Printing n uses repr
which gives the unicode "tag".  Something akin to this...thanks for
showing what i need to read up on...
-- 
http://mail.python.org/mailman/listinfo/python-list


Processing a large string

2011-08-11 Thread goldtech
Hi,

Say I have a very big string with a pattern like:

akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn.

I want to split the sting into separate parts on the "3" and process
each part separately. I might run into memory limitations if I use
"split" and get a big array(?)  I wondered if there's a way I could
read (stream?) the string from start to finish and read what's
delimited by the "3" into a variable, process the smaller string
variable then append/build a new string with the processed data?

Would I loop it and read it char by char till a "3"...? Or?

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


Can not uninstall activepython. Missing msi ?

2011-04-12 Thread goldtech
Hi,

I want to uninstall Active Python 2.6.2.2 and upgrade. Certain things
are not working and it's probably time to upgrade anyway. When I try
to uninstall it says "missing msi".

Before I delete all the folders and clean the registry out is there
something I can try to have a normal or more graceful uninstall? Using
WinXP.

Thanks,

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


Popen to get stdout and stderr for ffmpeg - No such file or directory ?

2011-04-18 Thread goldtech
Hi,

Trying to learn how to run a linux command and get the stdout and
stderr. I'm trying the following:

>>> cmd3 = r'ffmpeg -i /home/giga/Desktop/Guitar1.flv'
>>> p = Popen(cmd3, stdout=PIPE, stderr=PIPE)

Traceback (most recent call last):
  File "", line 1, in 
p = Popen(cmd3, stdout=PIPE, stderr=PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1141, in
_execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

But:

>>> if os.path.exists(r'/home/giga/Desktop/Guitar1.flv'):
print "exist"

exist
>>>

And just running ffmpeg alone seems as expected:

>>> cmd2=r'ffmpeg'
>>> p = Popen(cmd2, stdout=PIPE, stderr=PIPE)
>>> stdout, stderr = p.communicate()
>>> stdout
'Hyper fast Audio and Video encoder\nusage: ffmpeg [options] [[infile
options] -i infile]... {[outfile options] outfile}...\n\n'
>>> stderr
"FFmpeg version git-N-29152-g0ba8485, Copyright (c) 2000-2011 the
FFmpeg developers\n  built on Apr 16 2011 16:40:56 with gcc 4.4.5\n
configuration: --enable-gpl ...snip...

Also if I run the exact command (cmd3) in the terminal it works OK.
Why is it not finding the file? Thanks, help appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Popen to get stdout and stderr for ffmpeg - No such file or directory ?

2011-04-18 Thread goldtech

> Read The Fine 
> Manual:http://docs.python.org/library/subprocess.html#subprocess.Popen:

snip...
>
> Try instead:
> cmd3 = ['ffmpeg', '-i', '/home/giga/Desktop/Guitar1.flv']
>
> Cheers,
> Chris
> --http://blog.rebertia.com

No doubt, I should RTFM...you're right!

Yes, works like a charm now.

Thanks so much for the help. I really appreciate it!
-- 
http://mail.python.org/mailman/listinfo/python-list



Image processing to auto adjust colors in python ?

2011-05-16 Thread goldtech
Hi,

I'm processing thumbnails with python but one thing I need to do is to
auto-adjust an image for the "best" colors. I am using ffmpeg to get
thumbs three seconds into a video, sometimes  the image is too dark.
Normally I'd go into something like the windows program Irfan View and
do "Auto Adjust Colors", but I need a comand-line solution to
processes hundreds of images in a loop. I'm using Ubuntu and Python.
Is there an image precessing package i could use to do this?

thanks,

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


Trying to write beautifulsoup result to a file and get error message

2011-11-13 Thread goldtech
If I try:
...
soup = BeautifulSoup(ft3)
f = open(r'c:\NewFolder\clean4.html', "w")
f.write(soup)
f.close()

I get error message:

Traceback (most recent call last):
  File "C:\Documents and Settings\user01\Desktop\py\tb1a.py", line
203, in 
f.write(soup)
TypeError: expected a character buffer object

I want to write beautiful soup's result to a file, I am doing
something wrong. Help appreciated.

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


python shell that saves history of typed in commands that will persist between reboots

2011-11-15 Thread goldtech
Hi,

Using Windows. Is there a python shell that has a history of typed in
commands?

I don't need output of commands just what I typed it. I need it to
save between sessions - something that no shell seems to do. If I
reboot there will still be a command history somewhere.

Like bash history in Linux.

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


from PyQt4 import QtWebKit ImportError: DLL load failed

2012-01-18 Thread goldtech
Hi,

Using WinXP

I installed PyQt from http://www.riverbankcomputing.co.uk/software/pyqt/download

installation file: PyQt-Py2.7-x86-gpl-4.9-1

then tried:


Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from PyQt4 import QtWebKit

Traceback (most recent call last):
  File "", line 1, in 
from PyQt4 import QtWebKit
ImportError: DLL load failed: The specified procedure could not be
found.
>>>

This is a common problem when I google it but I don't see a clear
procedure for a fix.

Any help appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


frequency analysis of a DB column

2007-08-01 Thread goldtech
In Python 2.1 are there any tools to take a column from a DB and do a
frequency analysis - a breakdown of the values for this column?

Possibly a histogram or a table saying out of 500 records I have one
hundred and two "301" ninety-eight "212" values and three-hundred
"410"?

Is SQL the way to for this?

Of course there'd be 1000's of values

I'm not asking about connecting to the DB, just tools to collate and
tally this sort of thing.

Thanks,
Lee G.

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


Re: frequency analysis of a DB column

2007-08-04 Thread goldtech
Just wanted to thank the Posters for the help!

Thanks.

Lee G.


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


Submit web form only client-side with Python? COM?

2007-08-04 Thread goldtech
Say I have have an HTML form , the user hits the submit button and I
what text they enetered into a HTML form field is written to a file.

But I don't have PHP, JAVA the usual client or server sided layers to
write the data to a file, and I'm not to keen on JavaScript. Note: I
can not add or download anything, I must use what I have.

But I have Python 2.1 and I'm on a WinXP desktop with the win32.com,
and usual active-x objects, MS-Office ect - what'd normally locally on
an XP work station.

So I can present the user with an HTML form in it - but how can I
write the form data to a local file on my work station?

If there isn't a web form way, could there be another way to get a box
to come up with input fields with the capability to submit the data to
a file?

Thanks,
Lee G.

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


Client-side HTML form processing with Python?

2007-08-04 Thread goldtech
I want to have an HTML form from a local local html file write a text
field's data to a local text file.

I have no client or server side tools like PHP, JAVA. I don't know
JavaScript. I can not add anything to the workstation I am using. It's
going to have to be a client-side solution - there's no CGI on the
server, no PHP.

It's XP with MS-Office, so I guess I have the usual active-x, and I
have Python 2.1.

Is there a way?  Thanks,
Lee G.

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


Re: Client-side HTML form processing with Python?

2007-08-04 Thread goldtech
Looks like  Tkinter is the way to do it.

There's always a way with Python - good stuff!

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


C++ Runtime Library error message - Pythonwin?

2007-08-11 Thread goldtech

Hi,

Doing GIS [Geographic Information Systems] scripts.

I was running a batch clip script that worked OK for 126 iterations
 then I got the following message:

"Microsoft Visual C++ Runtime Library

program: C:\python21\pythonwin\pythonwin.exe

This application has requested the runtime to terminate in an unusual
 way. Please contact the applications support team for more
information."


What does this mean? Using XP. Is there a log on my system that gives
more info?

Thanks

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


Python syntax r prefix to a string

2007-08-19 Thread goldtech
Does anyone know this syntax and could link me to an explanation?

Something like:

Workspace = r'C:\foobar\mystuff\xyz'

What's that "r" doing? Sometimes I see a "u" too.

Explanation appreciated.

Thanks,
Lee G.

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


Parameter Passing - String Variable Truncated ?

2007-08-31 Thread goldtech
Hi,

I'm passing what I think is a string parameter to another Python
program (spawn.py)  - see the code snip below. But only the counter
part gets printed to a log file via  spawn.py. Yet the echo print to
the output window shows the whole string with the fc part. Better
explained below I hope, there's the calling .py and the spawn
script .py:
...snip...
while fc:
counter = counter + 1
fc_cntr = str(counter) + ' : ' + fc
print fc_cntr + '\n'  # Print to Pythonwin interactive window -
eg. "1 : New York" - all is printed OK

arglist = []
arglist.append(pythonPath)
arglist.append(spawn_script)
arglist.append(fc_cntr)  # This gets sent to the spawn_script but
only "1" gets printed

os.spawnv(os.P_WAIT, pythonPath, arglist)
fc = fcs.next()
...
--
## the spawn_script
import win32com.client, sys, os, time, re

in_featclass = sys.argv[1]
handle = open('C:\\log_file.txt', 'a')
handle.write(in_featclass + "\n") # ONLY the counter part gets printed
to the log file!Why?
--

Thanks, for help.

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


Re: Parameter Passing - String Variable Truncated ?

2007-08-31 Thread goldtech
snip...
> > --
>
> Try handle.write(repr(sys.argv[1:]) + "\n")
> and come back with your conclusions ... unless of course someone has
> spoonfed you in the meantime.
>
> Another clue: write yourself a little arg-dumper script and try
> running it in a Command Prompt window.
> 8<---
> import sys
> for x, arg in enumerate(sys.argv):
> print x, repr(arg)
> 8<---
> HTH,
> John

It's a list.

...
['5', ':', 'Alaska.shp']
['6', ':', 'Arizona.shp']
['7', ':', 'Arkansas.shp']
['8', ':', 'California.shp']
['9', ':', 'Colorado.shp']
['10', ':', 'Connecticut.shp']
['11', ':', 'Delaware.shp']
['12', ':', 'District', 'of', 'Columbia.shp']
['13', ':', 'Florida.shp']
['14', ':', 'West', 'Virginia.shp']
['15', ':', 'Wisconsin.shp']
['16', ':', 'Wyoming.shp']

Thanks,
Lee G.

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


tkinter question

2007-10-04 Thread goldtech
This works OK. But I notice that if I enlarge the window after the
script has run, the white listbox only gets "so" big while the grey
background enlarges.

Is there a way to have it all white when I enlarge a window - like
what normally happens?



from Tkinter import *
root = Tk()
root.title("Dirty Words")
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
listbox = Listbox(root, bg='white', font = "Courier 16", width=60)
listbox.pack()
i='123456789abcdefghijklmnopqrstuvwxyz'
for x in range(10):
listbox.insert(END, i)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
mainloop()

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


Re: tkinter question

2007-10-05 Thread goldtech

>
> try to change listbox.pack() to listbox.pack(expand=True, fill=BOTH)
> .. is it that you want ?

Yes.

>
>  -mykhal

Worked with TRUE all uppercase.

Exactly what I needed. Thank you.

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


Tkinter text widget

2007-10-06 Thread goldtech
I thought the "DISABLED" made it so I could not edit it. But it also
makes it so I can not scroll down. If you make the window smaller than
the content then try to put a cursor in there to use up/down arrow you
can't.

What I want is not to be able to change text content, but no other
action is disabled. Is this complicated to do?

Thanks.


from Tkinter import *
root = Tk()
text = Text(root, font=("Courier"))
text.pack()
i='123456789abcdefghijklmnopqrstuvwxyz\n'
for x in range(30):
text.insert(END, i)
text.config(state=DISABLED)
mainloop()

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


How to create a file on users XP desktop

2007-10-06 Thread goldtech
Can anyone link me or explain the following:

I open a file in a python script. I want the new file's location to be
on the user's desktop in a Windows XP environment.  fileHandle = open
(., 'w' )  what I guess I'm looking for is an environmental
variable that will usually be correct on most XP desktops and will
work in the open statement. Or is there another way?

Thanks

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


Re: Tkinter text widget

2007-10-07 Thread goldtech

> You can scroll, but you can't see the cursor. Use
>
> for x in range(30):
> text.insert(END, "%3d " % x + i)
>
> to check.
>
> ED

I tried it w/the line numbers. On my system I see 0-23.

But there is no way to scroll. Still the same result.

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


Re: How to create a file on users XP desktop

2007-10-07 Thread goldtech

>
>  This is really a Windows question, not a Python question. You should
> have been able to figure it out yourself by examining existing
> environment variables.

I agree, you're right. I learn more by figuring out the code myself.

After Google briefly:  In a DOS box type: SET

This was too easy - sorry.



>  Something like the code below should work for you if the standard
> environment variables haven't been hosed.
> --
> import os
> Filename = os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + "\\Desktop
> \MyNewFile"
> f = file(Filename, "w")
> f.write("Here's a file on the desktop\n")
> f.close()


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


Re: How to create a file on users XP desktop

2007-10-08 Thread goldtech

> from win32com.shell import shell, shellcon
>
> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>
> 
>

I have a general problem with using win32com. It's the documentation.
I never know what is available, what classes, methods, what they do.
Even some of the existing documentation admits existing documentation
is scant e.g. "you're just expected to know".

Other than the O'Reilly book. People say to browse COM with PythonWin.
When I try this I'm confronted with a dizzying array, there's tons of
stuff in there. Where's  win32com? If I find it will there be a
synopsis on each class, each classes methods? Will there be usage
examples?

If I'm wrong please educate me.

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


Re: Tkinter text widget

2007-10-08 Thread goldtech
On Oct 7, 11:00 am, Simon Forman <[EMAIL PROTECTED]> wrote:
> On Oct 6, 11:18 pm, goldtech <[EMAIL PROTECTED]> wrote:
>
>
>
> > I thought the "DISABLED" made it so I could not edit it. But it also
> > makes it so I can not scroll down. If you make the window smaller than
> > the content then try to put a cursor in there to use up/down arrow you
> > can't.
>
> > What I want is not to be able to change text content, but no other
> > action is disabled. Is this complicated to do?
>
> > Thanks.
>
> > from Tkinter import *
> > root = Tk()
> > text = Text(root, font=("Courier"))
> > text.pack()
> > i='123456789abcdefghijklmnopqrstuvwxyz\n'
> > for x in range(30):
> > text.insert(END, i)
> > text.config(state=DISABLED)
> > mainloop()
>
> I just tried this script.  You can select text and if you drap the
> selection outside the window then scrolling occurs, also Tk's default
> behavior of scrolling with the middle button still works (i.e. click-
> and-drag with the middle button to scroll.)

Yes, if I depress the mouse's scroll wheel (the middle button) I can
drag the content up/down. Interesting...I didn't know that. But I
can't select, XP Python 2.1.

I'll try adding scroll bars. Thanks.

...snip...

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


Re: How to create a file on users XP desktop

2007-10-08 Thread goldtech

> from win32com.shell import shell, shellcon
>
> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>
> 

Tim,

How did you learn Win32com?

Other than the O'Reilly book, I've never found a lot of
documentation.

Trying to browse COM in PythonWin is tough - there's tons of stuff in
there. I've never been able to find the Win32com classes, methods,
usage examples when I browse COM in PythonWin.

For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
officially documented?

Did you learn from using Visual C++ or VB? How did you learn this
stuff?

Thanks,
Lee G.

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


Re: Tkinter text widget

2007-10-08 Thread goldtech
After some Google searching I found "ScrolledText", this does what I
want :^)


from Tkinter import *
from ScrolledText import ScrolledText
root = Tk()
text = ScrolledText(root, font=("Courier"))
ScrolledText
text.pack()
i='123456789abcdefghijklmnopqrstuvwxyz\n'
for x in range(30):
text.insert(END, "%3d " % x + i)
text.config(state=DISABLED)
mainloop()

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


A Python way to get MS Access table column information?

2007-10-15 Thread goldtech
Using Python and OBDC in MS-Access DBs. So, I'm able to run SQL
statements from Python on an Access DB.

Is there an SQL statement that will give me column information? For a
table I want to know the data type and of course colum/Attribute name
for each column.

So far the answer has been "no". VB or some other tool is needed to do
that I'm told.

Using just Python and OBDC is there a way? Maybe Win32com?

Thanks

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


Test for a unicode string

2007-10-24 Thread goldtech
Hi,

I have a regular expression test in a script. When a unicode character
get tested in the regex it gives an error:

UnicodeError: ASCII decoding error: ordinal not in range(128)

Question: Is there a way to test a string for unicode chars (ie. test
if a string will throw the error cited above).

Like:
 if  unicode string:
  print  'string's line #'
 else:
  process the string

How do I do "if unicode string" cited in pseudo-code above?

Thanks, still using Python 2.1

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


Re: Test for a unicode string

2007-10-25 Thread goldtech
snip...
> > Like:
> >  if  unicode string:
> >   print  'string's line #'
> >  else:
> >   process the string
>

If I use "re.UNICODE"  like:  m = re.match(r"\w+", s, re.UNICODE)

then it seems to fix my problem.  Trying to read as much as I can on
unicode

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


Win32.com

2007-11-13 Thread goldtech
Given WinXP. I remove Pythonwin and it seems I lose  win32.com. I
can't import win32.com  Is win32.com bundled with Pythonwin?

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


Tk Tkinter : multiple file selection dialog over multiple directories ?

2007-12-14 Thread goldtech
Hi, TKinter question

Let's say I use:
...

files = tkFileDialog.askopenFilenames(filetypes=[('AccessDB Files',
'*.mdb')])

...

This works OK - I can select multiple files and the var "files" will
be a tuple of the files.

But let's say the files I want to select are in different folders/
directories, when I select a file then go to a different dir and try
to select a 2nd file it overwrites the 1st file entree.

Is there a way for multiple file selection over different directories?
With a dialog box or another way?

Thanks. Using Python 2.4.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Python ADO Date Time database fields

2008-01-24 Thread goldtech
Hi,

Given an MS-Access table with a date type field with a value of:
12:00:00 AM - just"12:00:00 AM", there's nothing else in the field.

I want to print exactly what's in the field, ie. "12:00:00 AM". What I
get printed is:   12/30/0/ 00:00:00

I try:

import win32com.client
from win32.client import Dispatch

oConn=Dispatch('ADODB.Connection')
db = r'C:\mydb.mdb'
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; data Source="+db)
oRS = Dispatch('ADODB.RecordSet')
oRS.ActiveConnection =  oConn
c = oConn.OpenSchema(20)

while not c.EOF:
tn = c.Fields.Item('Table_Name').Value
oRS.Open(tn)
(oRS, dt) = oConn.Execute('SELECT date_field FROM '+tn+' GROUP BY
date_field')
while not oRS.EOF:
print oRS.Fields(dt).Value  # print here
 oRS.MoveNext()
c.MoveNext()

oRS.Close()
oConn.Close()
# end

What I get printed is:   12/30/0/ 00:00:00

What do I to get exactly what's in the field?

Thanks,

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


Re: Python ADO Date Time database fields

2008-01-25 Thread goldtech
snip
>
> try this:
>
> val = oRS.Fields(dt).Value
> print type(val)

this gives:  



> print float(val)

yes, it gives 0.0

But there should be a way to print what is *actually in the field*.
When I open the DB table in Access I see: 12:00:00 AM.

That's what I want - the value, and the form of the value, exactly as
seen in the field...

As an aside, the roughly eqivalent code in Perl will print the
"12:00:00 AM" - (the trick for the date types in Perl is to add: "use
Win32::OLE::Variant;"

There has to be a way:^)

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


SAX XML Parse Python error message

2008-07-13 Thread goldtech
SAX XML Parse Python error message
Hi,
My first attempt at SAX, but have an error message I need help with.

I cite the error message, code, and xml below.

Be grateful if anyone can tell me what the fix is.
Thanks.


>>>
Traceback (most recent call last):
File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework
\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\pythonscripts\xml\parse3.py", line 43, in ?
parser.parse(r'C:\perlscripts\xml\Document2.kml')
File "C:\Python24\lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\Python24\lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
File "C:\Python24\lib\xml\sax\expatreader.py", line 207, in feed
self._parser.Parse(data, isFinal)
File "C:\Python24\lib\xml\sax\expatreader.py", line 303, in
end_element
self._cont_handler.endElement(name)
File "C:\pythonscripts\xml\parse3.py", line 39, in endElement
print self.description, str(self.coordinates)
AttributeError: G_Handler instance has no attribute 'coordinates'
>>>


Code:

from xml.sax import make_parser
from xml.sax.handler import ContentHandler
import string

class G_Handler(ContentHandler):

def __init__ (self):
self.isFolderElement = 0
self.isdescriptionElement = 0
self.iscoordinatesElement = 0

def startElement(self, name , attrs):
if name == 'Folder':
self.isFolderElement= 1
self.Folder = ""
if name == 'description':
self.isdescriptionElement= 1
self.description = ""
if name == 'coordinates':
self.iscoordinatesElement = 1
self.coordinates = ""


def characters (self, ch):
if self.isFolderElement == 1:
self.Folder = ch
if self.isdescriptionElement == 1:
self.description = ch
if self.iscoordinatesElement == 1:
self.coordinates = ch

def endElement(self, name):
if name == 'Folder':
self.isFolderElement = 0
if name == 'description':
self.isdescriptionElement= 0
if name == 'coordinates':
self.iscoordinatesElement = 0
print  self.description, str(self.coordinates)

parser = make_parser()
parser.setContentHandler(G_Handler())
parser.parse(r'C:\perlscripts\xml\Document2.kml')






abc


-84.4, 33.7


abc


-86.7, 36.1


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


Re: SAX XML Parse Python error message

2008-07-13 Thread goldtech
I would be grateful for support with the code I cited. It's not long
and fairly standard. I'm sure my error(s) would be glaring to more
experienced coders. I appreciated the "heads-up" about other options
but I would be grateful for help getting this code to run. Thanks



On Jul 13, 11:47 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> goldtech wrote:
> > My first attempt at SAX, but have an error message I need help with.
>
> Just in case you prefer writing readable code over debugging SAX code into
> existence, try lxml.
>
> http://codespeak.net/lxml/
>
> Here is a presentation you might find interesting.
>
> http://codespeak.net/lxml/s5/lxml-ep2008.html
>
> Stefan

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


Re: SAX XML Parse Python error message

2008-07-13 Thread goldtech
On Jul 13, 5:30 pm, Waldemar Osuch <[EMAIL PROTECTED]> wrote:
> On Jul 13, 3:00 pm, goldtech <[EMAIL PROTECTED]> wrote:
>
> > I would be grateful for support with the code I cited. It's not long
> > and fairly standard. I'm sure my error(s) would be glaring to more
> > experienced coders. I appreciated the "heads-up" about other options
> > but I would be grateful for help getting this code to run. Thanks
>
> Initialize self.coodinates in the __init__
> or indent the "print  self.description, str(self.coordinates)"
> one more level.
> You have to remember that "endElement" is being called on the end
> of every element.  In your case it is called by  but
> the parser did not see  yet.
>
> In "def characters" you should be collecting the "ch" in a buffer.
> It may be called multiple times for the same element.
> Something like "self.description += ch" would do for starters.
>
> Also you do not need to convert self.coordinates to string before
> printing, it is already a string and even if it was not "print"
> would convert it for you.
>
> That's it for now :-) Others may spot more issues with
> your code or my response.
> On the positive side I really liked how you asked
> the question.  There was a short runnable example and traceback.
>
> Waldemar

Putting the print statements were they won't cause trouble and
using ...+= ch (vs. only =) in the character section fixed it:

...
def endElement(self, name):
...
if name == 'description':
self.isdescriptionElement= 0
print  self.description
if name == 'coordinates':
self.iscoordinatesElement = 0
print self.coordinates
...

I need to read your answer again carefully - I don't know if what I
did is best - but it seemed to fix it. Thank you for the clear and
cogent answer.

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


Python base distribution come with a validating XML parser?

2008-07-25 Thread goldtech
Hi,

Basic XML questions,

I have a .xml file I want to validate against a .xsd file...

Does the Python base distribution come with a validating XML parser?

I want to make sure the elements in my xml file vs. the elements
defined in my xsd are a match.

I could parse both XML and xsd elements to lists and compare the
lists, but I imagine the validation process can do this too...

Some of this is basic stuff - just a link to a site or doc is
sufficient.

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


String manipulation questions

2008-04-09 Thread goldtech
Hi,

Replacing strings in a text (likely an XML) file. Some newbie
questions...

...
while line:
counter=counter+1
if line.find(newstring) != -1:
print 'match at line'+str(counter)
newline = line.replace(oldstring, newstring)
fileOUT.write(newline)
line=fileIN.readline()


Question1: The replace method - If a string does not have the target
replacement "newstring", then newline equals oldstring? Ie. oldstring
is not changed in any way? Seems to be what I observe but just want to
confirm this.

Question2:  I'm using "line.find(newstring) != -1..."  because I want
to print when a replacement happens. Does "line.replace..." report
indirectly somehow when it replaces?
Thanks

P.S. I know I should be using XSLT to transform XML -  but the above
seems to work for small text changes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String manipulation questions

2008-04-09 Thread goldtech
snip...
>
>for counter, line in enumerate(fileIN):
>newline = line.replace(oldstring, newstring)
>if newline != line:
>print 'match at line', counter+1
>fileOUT.write(newline)

"enumerate" - haven't seen that before. Nice!

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


Tkinter scrollbar and checkbox

2008-04-24 Thread goldtech

Hi,

I'm stumped on how to have a scrollbar with a long list of checkboxes.
Given code like:

from Tkinter import *
root = Tk()
states = []
for i in range(150):
var = IntVar()
chk = Checkbutton(root, text=str(i), variable=var)
chk.grid(sticky=W)
states.append(var)
root.mainloop()
print map((lambda var: var.get()), states)

I've tried adding this to a frame then adding the frame to a canvas
and it gets complicated rather quickly...

Is there a simple way to add a scroll bar?

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


Re: Tkinter scrollbar and checkbox

2008-04-25 Thread goldtech
snip...
>
> I use wxPython most of the time, however effbot has a good tutorial on
> scrollbars for Tkinter that I think you might find helpful:
>
> http://effbot.org/zone/tkinter-scrollbar-patterns.htm
>
> Here's another link on the subject:
>
> http://www.pythonware.com/library/tkinter/introduction/scrollbar.htm
>
> HTH
>
> Mike

Indeed, I see it:

http://effbot.org/zone/tkinter-autoscrollbar.htm

Many Thanks.

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


Installed modules from Synaptic in Ubuntu problem

2010-11-20 Thread goldtech
Hi,

Using Ubuntu linux 9.04 and have python 2.6. I'm trying to add a
module from the synaptic installer. It's µTidylib a wrapper for HTML
Tidy. It installed with out a problem, when I do a  $ help ('modules')
I see a module called "tidy". But when I do an import tidy in a script
I get an error...
import tidy
ImportError: No module named tidy

How do I get this module working? Any help appreciated.

also do I need a special path?:

~$ locate utidylib
/usr/share/doc/python-utidylib
/usr/share/doc/python-utidylib/README.Debian
/usr/share/doc/python-utidylib/README.Debian-source
/usr/share/doc/python-utidylib/README.txt
/usr/share/doc/python-utidylib/changelog.Debian.gz
/usr/share/doc/python-utidylib/copyright
/usr/share/python-support/python-utidylib
/usr/share/python-support/python-utidylib/tidy
/usr/share/python-support/python-utidylib/uTidylib-0.2.egg-info
/usr/share/python-support/python-utidylib/tidy/__init__.py
/usr/share/python-support/python-utidylib/tidy/error.py
/usr/share/python-support/python-utidylib/tidy/lib.py
/usr/share/python-support/python-utidylib/tidy/test_tidy.py
/var/cache/apt/archives/python-utidylib_0.2-3.2ubuntu1_all.deb
/var/lib/dpkg/info/python-utidylib.list
/var/lib/dpkg/info/python-utidylib.md5sums
/var/lib/dpkg/info/python-utidylib.postinst
/var/lib/dpkg/info/python-utidylib.prerm

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


How to install uTidylib, easy_install problem

2010-11-22 Thread goldtech
I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2
with easy_install.  I like uTidylib more vs. newer modules.and want to
use it. I get output below. How do I install it? I do see it in
http://pypi.python.org/simple/uTidylib/

Thanks.

C:\Documents and Settings\user1>easy_install uTidylib
install_dir C:\Python26\Lib\site-packages\
Searching for uTidylib
Reading http://pypi.python.org/simple/uTidylib/
Reading http://utidylib.sf.net
No local packages or download links found for uTidylib
error: Could not find suitable distribution for
Requirement.parse('uTidylib')

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


list of regex special characters

2010-11-28 Thread goldtech
I am looking for a list of special character in python regular
expressions that need to be escaped if you want their literal meaning.

I searched and can not find the list. Any help appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


regular expression help

2010-11-29 Thread goldtech
Hi,

say:
>>> import re
 m="cccvlvlvlvnnnflfllffccclfnnnooo"
>>> re.compile(r'ccc.*nnn')
>>> rtt=.sub("||",m)
>>> rtt
'||ooo'

The regex is eating up too much. What I want is every non-overlapping
occurrence I think.

so rtt would be:

'||flfllff||ooo'

just like findall acts but in this case I want sub to act like that.

Thanks

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


Re: regular expression help

2010-11-29 Thread goldtech
 .*?  fixed it. Every occurrence of the pattern is now affected, which
is what I want.

Thank you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


SAX unicode and ascii parsing problem

2010-11-30 Thread goldtech
Hi,

I'm trying to parse an xml file using SAX. About half-way through a
file I get this error:

Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework
\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
  File "E:\sc\b2.py", line 58, in 
parser.parse(open(r'ppb5.xml'))
  File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
  File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
  File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed
self._parser.Parse(data, isFinal)
  File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in
end_element
self._cont_handler.endElement(name)
  File "E:\sc\b2.py", line 51, in endElement
d.write(csv+"\n")
UnicodeEncodeError: 'ascii' codec can't encode characters in position
146-147: ordinal not in range(128)

I'm using ActivePython 2.6. I trying to figure out the simplest fix.
If there's a Python way to just take the source XML file and covert/
process it so this will not happen - that would be best. Or should I
just update to Python 3 ?

I tried this but nothing changed, I thought this might convert it and
then I'd paerse the new file - didn't work:

uc = open(r'E:\sc\ppb4.xml').read().decode('utf8')
ascii = uc.decode('ascii')
mex9 = open( r'E:\scrapes\ppb5.xml', 'w' )
mex9.write(ascii)

Again I'm looking for something simple even it's a few more lines of
codes...or upgrade(?)

Thanks, appreciate any help.
mex9.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


SAX unicode and ascii parsing problem

2010-11-30 Thread goldtech
Hi,

I'm trying to parse an xml file using SAX. About half-way through a
file I get this error:

Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework
\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
  File "E:\sc\b2.py", line 58, in 
parser.parse(open(r'ppb5.xml'))
  File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
  File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
  File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed
self._parser.Parse(data, isFinal)
  File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in
end_element
self._cont_handler.endElement(name)
  File "E:\sc\b2.py", line 51, in endElement
d.write(csv+"\n")
UnicodeEncodeError: 'ascii' codec can't encode characters in position
146-147: ordinal not in range(128)

I'm using ActivePython 2.6. I trying to figure out the simplest fix.
If there's a Python way to just take the source XML file and covert/
process it so this will not happen - that would be best. Or should I
just update to Python 3 ?

I tried this but nothing changed, I thought this might convert it and
then I'd paerse the new file - didn't work:

uc = open(r'E:\sc\ppb4.xml').read().decode('utf8')
ascii = uc.decode('ascii')
mex9 = open( r'E:\scrapes\ppb5.xml', 'w' )
mex9.write(ascii)

Again I'm looking for something simple even it's a few more lines of
codes...or upgrade(?)

Thanks, appreciate any help.
mex9.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SAX unicode and ascii parsing problem

2010-11-30 Thread goldtech
snip...
>
> I'm just as stumped as I was when you first asked this question 13
> minutes ago. ;-)
>
> regards
>  Steve
>
snip...

Hi Steve,

Think I found it, for example:

line = 'my big string'
line.encode('ascii', 'ignore')

I processed the problem strings during parsing with this and it works
now. Got this from:

http://stackoverflow.com/questions/2365411/python-convert-unicode-to-ascii-without-errors


Best, Lee

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


Python's equivalent to Main calling program and subprograms

2010-12-01 Thread goldtech
Hi,

Could someone link me to info - I'm sure this is commonly done:

"Long ago" with Fortran and Pascal there was a pattern used a lot. It
was like:

Start
Main
Global Var
Subprogram1
Subprogram2
Subprogram3
End of Main
End

The global var was a var that all the subprograms could access. I
wanted a container for several scripts that run in succession one
after dhere other.  This has to be newbie stuff - sorry to ask. If you
could give me some keywords or link me or provide a simple example I
would be grateful.

Thanks

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


import module doesn't work for new package

2010-12-03 Thread goldtech
I tried install a Python - would the word be "package"? - on Ubuntu
10.10. Could you tell me how to fix? I would be grateful, is it a path
problem? Thanks. Lee

gi...@giga1:~/Desktop/pykhtml-0.2$ sudo python setup.py install
[sudo] password for giga1:
running install
running build
running build_py
creating build
creating build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/pykhtml
copying pykhtml/dom.py -> build/lib.linux-i686-2.6/pykhtml
copying pykhtml/__init__.py -> build/lib.linux-i686-2.6/pykhtml
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info
Writing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info

then:

>>> import pykhtml
Traceback (most recent call last):
  File "", line 1, in 
  File "pykhtml/__init__.py", line 3, in 
import khtml, kdecore, kdeui, kio, dcopext
ImportError: No module named khtml
-- 
http://mail.python.org/mailman/listinfo/python-list


assigning multi-line strings to variables

2010-04-27 Thread goldtech
Hi,

This is undoubtedly a newbie question. How doI assign variables
multiline strings? If I try this i get what's cited below. Thanks.


>>> d="d
d"
>>> d
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'd' is not defined
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assigning multi-line strings to variables

2010-04-27 Thread goldtech
On Apr 27, 7:31 pm, Brendan Abel <007bren...@gmail.com> wrote:
> On Apr 27, 7:20 pm, goldtech  wrote:
>
> > Hi,
>
> > This is undoubtedly a newbie question. How doI assign variables
> > multiline strings? If I try this i get what's cited below. Thanks.
>
> > >>> d="d
> > d"
> > >>> d
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > NameError: name 'd' is not defined
>
> d = "d"\
>     "d"
>
> or
>
> d = "dd\
> dd"
>
> You don't need the trailing slash in the first example if you are
> writing this in a script, python assumes it.

Thanks but what if the string is 500 lines. Seems it would be hard to
put a "\" manually at the end of every line. How could i do that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assigning multi-line strings to variables

2010-04-27 Thread goldtech
On Apr 27, 7:33 pm, MRAB  wrote:
> goldtech wrote:
> > Hi,
>
> > This is undoubtedly a newbie question. How doI assign variables
> > multiline strings? If I try this i get what's cited below. Thanks.
>
> >>>> d="d
> > d"
> >>>> d
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > NameError: name 'd' is not defined
>
> Use a triple-quoted string literal:
>
>  >>> d = """d
> ... d"""
>  >>> d
> 'd\nd'

Only seems to work when there's a '... ' on the 2nd line. I need a way
to assign large blocks of text to a variable w/out special formatting.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assigning multi-line strings to variables

2010-04-29 Thread goldtech
Thank you to posters for help to my question. Seems I had trouble with
triple quotes strings in the PythonWin shell. But using the Idle shell
things work as expected. But this is probably another issue...any way,
w/Idle's shell I got the "action" regarding multiline strings I
expected.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python's regular expression help

2010-04-29 Thread goldtech
Hi,
Trying to start out with simple things but apparently there's some
basics I need help with. This works OK:
>>> import re
>>> p = re.compile('(ab*)(sss)')
>>> m = p.match( 'absss' )
>>> m.group(0)
'absss'
>>> m.group(1)
'ab'
>>> m.group(2)
'sss'
...
But two questions:

How can I operate a regex on a string variable?
I'm doing something wrong here:

>>> f=r'abss'
>>> f
'abss'
>>> m = p.match( f )
>>> m.group(0)
Traceback (most recent call last):
  File "", line 1, in 
m.group(0)
AttributeError: 'NoneType' object has no attribute 'group'

How do I implement a regex on a multiline string?  I thought this
might work but there's problem:

>>> p = re.compile('(ab*)(sss)', re.S)
>>> m = p.match( 'ab\nsss' )
>>> m.group(0)
Traceback (most recent call last):
  File "", line 1, in 
m.group(0)
AttributeError: 'NoneType' object has no attribute 'group'
>>>

Thanks for the newbie regex help, Lee
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's regular expression help

2010-04-29 Thread goldtech
On Apr 29, 11:49 am, Tim Chase  wrote:
> On 04/29/2010 01:00 PM, goldtech wrote:
>
> > Trying to start out with simple things but apparently there's some
> > basics I need help with. This works OK:
> >>>> import re
> >>>> p = re.compile('(ab*)(sss)')
> >>>> m = p.match( 'absss' )
>
> >>>> f=r'abss'
> >>>> f
> > 'abss'
> >>>> m = p.match( f )
> >>>> m.group(0)
> > Traceback (most recent call last):
> >    File "", line 1, in
> >      m.group(0)
> > AttributeError: 'NoneType' object has no attribute 'group'
>
> 'absss' != 'abss'
>
> Your regexp looks for 3 "s", your "f" contains only 2.  So the
> regexp object doesn't, well, match.  Try
>
>    f = 'absss'
>
> and it will work.  As an aside, using raw-strings for this text
> doesn't change anything, but if you want, you _can_ write it as
>
>    f = r'absss'
>
> if it will make you feel better :)
>
> > How do I implement a regex on a multiline string?  I thought this
> > might work but there's problem:
>
> >>>> p = re.compile('(ab*)(sss)', re.S)
> >>>> m = p.match( 'ab\nsss' )
> >>>> m.group(0)
> > Traceback (most recent call last):
> >    File "", line 1, in
> >      m.group(0)
> > AttributeError: 'NoneType' object has no attribute 'group'
>
> Well, it depends on what you want to do -- regexps are fairly
> precise, so if you want to allow whitespace between the two, you
> can use
>
>    r = re.compile(r'(ab*)\s*(sss)')
>
> If you want to allow whitespace anywhere, it gets uglier, and
> your capture/group results will contain that whitespace:
>
>    r'(a\s*b*)\s*(s\s*s\s*s)'
>
> Alternatively, if you don't want to allow arbitrary whitespace
> but only newlines, you can use "\n*" instead of "\s*"
>
> -tkc

Yes, most of my problem is w/my patterns not w/any python re syntax.

I thought re.S will take a multiline string with any spaces or
newlines and make it appear as one line to the regex. Make "/n" be
ignored in a way...still playing w/it. Thanks for the help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Idle text wrap

2009-08-13 Thread goldtech
Hi,

I'm using Idle interactive shell. Actually Idle-Spoon which has a few
nice extensions and Python 2.6 on Linux. When I

 print str_value + "\n"

Where str_value is for example a string of 120 chars.

I notice that the lines seem to get hard wrapped at around 80. Is
there a way I can config it to either wrap to the window, or for a
higher amount before wrapping?

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


Python "and" behavior

2009-08-13 Thread goldtech
Could you explain or link me to an explanation of this? Been using
Python for a while but not sure I understand what's happening below.
Thanks.


>>> ss=1 and "f"
>>> ss
'f'
>>> ss=0 and "f"
>>> ss
0
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Idle does not recognize PYTHONPATH

2009-08-22 Thread goldtech
Hi,

Idle does not recognize PYTHONPATH set in .bashrc. Starting Python
shell in the terminal sys.path shows the PYTHONPATH, but again not
shown in IDLE. This is a common problem but I could not find a fix.
Using Ubuntu 9.04. Python 2.6.

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