Re: Difficulties configuring LTO on macOS with clang

2019-07-16 Thread scott
Hmm, removing the path didn’t help either.

I ended up defining the `LLVM_AR=/path/to/homebrew/llvm-ar` environment 
variable after installing clang from brew. I was worried that there would be 
problems using ar from a different version of the toolchain than the compiler, 
but things seem to have worked properly.

I guess llvm-ar just isn’t packaged with macOS?

In any case, this problem is solved for me now.

Thanks for your help,
Scott
On Jul 10, 2019, 16:22 -0400, Barry Scott , wrote:
>
>
> > On 10 Jul 2019, at 15:25, Scott Colby  wrote:
> >
> > Unfortunately that path is absent on my system. Could the issue be that the 
> > llvm version of ar is not present at all on macOS? What remains confusing 
> > in that case is that by using CC=cc (and I assume just ar) the LTO 
> > compilation succeeds, despite cc being a symlink to clang anyway.
>
> Oh that may be because I have MacPorts installed on my mac
> I guess you have macPorts installed as well?
>
> I see you are using brew openssl. Maybe the macPorts tools
> and the brew tools are conflicting?
>
> What if you remove /opt/local/bin from your PATH does that help configure 
> find the tools it needs?
>
> Barry
>
>
>
>
> >
> > Thanks,
> > Scott
> >
> > On Tue, Jul 9, 2019, at 15:39, Barry Scott wrote:
> > >
> > >
> > > > On 9 Jul 2019, at 19:28, Scott Colby  wrote:
> > > >
> > > > Hello all,
> > > >
> > > > I am having difficulty building Python with `--with-lto` on macOS 
> > > > 10.14.5. With a clean checkout of the CPython source at the tagged 
> > > > release for 3.7.4, I ran:
> > > >
> > > > $ ./configure --prefix=/opt/python3.7.4 --enable-optimizations 
> > > > --enable-ipv6 --with-lto --with-openssl=$(brew --prefix openssl) 
> > > > CC=clang
> > > > checking for git... found
> > > > checking build system type... x86_64-apple-darwin18.6.0
> > > > checking host system type... x86_64-apple-darwin18.6.0
> > > > checking for python3.7... python3.7
> > > > checking for --enable-universalsdk... no
> > > > checking for --with-universal-archs... no
> > > > checking MACHDEP... checking for --without-gcc... no
> > > > checking for --with-icc... no
> > > > checking for gcc... clang
> > > > checking whether the C compiler works... yes
> > > > checking for C compiler default output file name... a.out
> > > > checking for suffix of executables...
> > > > checking whether we are cross compiling... no
> > > > checking for suffix of object files... o
> > > > checking whether we are using the GNU C compiler... yes
> > > > checking whether clang accepts -g... yes
> > > > checking for clang option to accept ISO C89... none needed
> > > > checking how to run the C preprocessor... clang -E
> > > > checking for grep that handles long lines and -e... /usr/bin/grep
> > > > checking for a sed that does not truncate output... /usr/bin/sed
> > > > checking for --with-cxx-main=... no
> > > > checking for clang++... no
> > > > configure:
> > > >
> > > >  By default, distutils will build C++ extension modules with "clang++".
> > > >  If this is not intended, then set CXX on the configure command line.
> > > >
> > > > checking for the platform triplet based on compiler characteristics... 
> > > > darwin
> > > > checking for -Wl,--no-as-needed... no
> > > > checking for egrep... /usr/bin/grep -E
> > > > checking for ANSI C header files... yes
> > > > checking for sys/types.h... yes
> > > > checking for sys/stat.h... yes
> > > > checking for stdlib.h... yes
> > > > checking for string.h... yes
> > > > checking for memory.h... yes
> > > > checking for strings.h... yes
> > > > checking for inttypes.h... yes
> > > > checking for stdint.h... yes
> > > > checking for unistd.h... yes
> > > > checking minix/config.h usability... no
> > > > checking minix/config.h presence... no
> > > > checking for minix/config.h... no
> > > > checking whether it is safe to define __EXTENSIONS__... yes
> > > > checking for the Android API level... not Android
> > > > checking for --with-suffix...
> > > > checking for case-insensitive build directory... yes
> > > > checking LIBRARY... libpython$(VERSION)$(ABIFLAGS).a
> > > > checking LINKCC... 

Apache/mod_python & MySQLdb

2005-01-12 Thread scott
AIUI, global variables are supposed to be preserved within each Apache 
thread/prcoess.

However, I'm importing and using MySQLdb within a class in a separate 
module, which is in turn imported and used within a _function (ie. not 
"published").  So, AFAICT, it's not supposed to be preseved.

But unless I specifically close() the database connection, it gets 
stranded and I eventually run out of connections, even if I del the 
connection and cursor objects.

What gives?  What happened to GC?
Also, is there an easy way to run pychecker on mod_python scripts?  It 
fails since _apache doesn't exist outside of Apache

regards,
Confused & tired of PHP.
--
http://mail.python.org/mailman/listinfo/python-list


help with wxSlider & wxPython

2005-01-17 Thread Scott
I have the code below.  I have changed the background of the frame to
white, but I cannot get the wxSlider to not be the ugly gray color.
Can someone tell me how to change it to a transparent background (I
tried wxTRANSPARENT_WINDOW without success)?

import os
from wxPython.wx import *
ID_ABOUT=101
ID_EXIT=110
class MainWindow(wxFrame):
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,wxID_ANY, title, size = (
800,600),style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
#self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE)
wxStaticText(self, -1, "Distance to Move", (30, 40))
slider = wxSlider(self, 100, 25, 0, 3600, (30, 60), (400,
-1),wxSL_HORIZONTAL | wxSL_TOP | wxSL_AUTOTICKS | wxSL_LABELS |
wxTRANSPARENT_WINDOW)
slider.SetTickFreq(1, 1)
slider.SetValue(1800)
self.CreateStatusBar() # A StatusBar in the bottom of the
window
# Setting up the menu.
filemenu= wxMenu()
filemenu.Append(ID_ABOUT, "&About"," Version 001")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wxMenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame
content.
EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
EVT_MENU(self, ID_EXIT, self.OnExit)   # attach the menu-event
ID_EXIT to the
self.SetBackgroundColour(wxWHITE)
self.Show(true)
self.Center(wxBOTH)
def OnAbout(self,e):
d= wxMessageDialog( self, "test","About test", wxOK)
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(true)  # Close the frame.
app = wxPySimpleApp()
frame = MainWindow(None, -1, "test")
app.MainLoop()

TIA,
Scott

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


how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread scott
hi people,

can someone tell me, how to use a class like that* (or "simulate" more 
than 1 constructor) :
#--
class myPointClass:
   def __init__(self, x=0, y=0):
 self.x = x
 self.y = y
   def __init__(self, x=0, y=0, z=0):
 self.__init__(self, x, y)
 self.z = z
#--

tia people
scott

*this is not homework
-- 
http://mail.python.org/mailman/listinfo/python-list


regulars expressions ?

2005-06-28 Thread scott
hi people !


i got some trouble with regular expressions
i need to split a string like this on the ',' character :

mystring = ""\test1, test2\", test, 42"

i wanna get something (a list) like this (3 elements) :
"test1, test2"
test
42

but the only thing i get is a list like this (4 elements) :
"test1"
"test2"
test
42

each element is separated by ',' but 1st element which is delimited by 
'"' may contain ',' character inside.

so the regular expression i need is something like :
split each element using ',' delimiter but if ',' delimiter is included 
between '"' please do not split


1st question is : does someone has understood the question ?
2nd question is : does someone has an answer ?

thanks people

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


Help with C extensions under VC6 / WinXP and Python 2.4

2005-02-16 Thread Scott
I've installed Python 2.4 under WinXP and am attempting to
create an extension module using the steps outlined here:
http://python.org/doc/2.4/ext/win-cookbook.html
I'm specifically trying to perform step 6. Creating a brand
new project using VC6.
The trouble I have is that there are no PC or PCbuild
subdirectories in C:\Python24.  Where do I find these?
Ultimately, what I want to do is interface some Python
code with a DLL that controls an A/D board.  I expect
I'll need to write an extension module to act as a shim
between this DLL and the Python code.
Scott
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with C extensions under VC6 / WinXP and Python 2.4

2005-02-16 Thread Scott

John Machin wrote:
> On Wed, 16 Feb 2005 20:57:18 -0500, Scott
> <[EMAIL PROTECTED]> wrote:
>
>
>>I've installed Python 2.4 under WinXP and am attempting to
>>create an extension module using the steps outlined here:
>>http://python.org/doc/2.4/ext/win-cookbook.html
>>
>>I'm specifically trying to perform step 6. Creating a brand
>>new project using VC6.
>>
>>The trouble I have is that there are no PC or PCbuild
>>subdirectories in C:\Python24.  Where do I find these?
>
>
> As the quoted URL says (2nd para):
> """
> To build extensions using these instructions, you need to have a copy
> of the Python sources of the same version as your installed Python.
> [snip]
> The example files described here are distributed with the Python
> sources in the PC\ example_nt\ directory
> """
>
> i.e. you have to download a copy of the Python source distribution.
Since I had an include directory, I assumed (incorrectly) that
I already had the sources.  Thanks for the reiteration -- it's
what I needed.
>
>
>>Ultimately, what I want to do is interface some Python
>>code with a DLL that controls an A/D board.  I expect
>>I'll need to write an extension module to act as a shim
>>between this DLL and the Python code.
>
>
> Possibly not; check out the ctypes module --
> http://starship.python.net/crew/theller/ctypes/
Thanks for the pointer.  This looks promising.
Scott
--
http://mail.python.org/mailman/listinfo/python-list


Matplotlib, py2exe and pytz

2005-02-18 Thread scott
I am trying to convert a python app that uses matplotlib to a
standalone executable using py2exe.

After running py2exe and executing my app I get the following stack
trace:

Traceback (most recent call last):
  File "gcToCsv.py", line 5, in ?
  File "plot_output.pyc", line 1, in ?
  File "pylab.pyc", line 1, in ?
  File "matplotlib\pylab.pyc", line 194, in ?
  File "matplotlib\axes.pyc", line 46, in ?
  File "matplotlib\dates.pyc", line 94, in ?
  File "pytz\__init__.pyc", line 53, in timezone
KeyError: 'UTC'

It appears that the instructions on the matplotlib web site and wiki
are incomplete and the pytz.zoneinfo package is not being included in
the finished dist directory.

I tried adding an opt line to setup.py
opts = {"py2exe": {"packages": ["pytz\zoneinfo"] } }
but still no joy.

Can someone tell me the correct setup.py file to use for including
matplotlib with an app using py2exe?

Thanks,

Scott

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


Re: Matplotlib, py2exe and pytz

2005-02-19 Thread scott
I unzipped library.zip to see what compiled python files were included
in the zip.
As in the error stacktrace the Pytz.timezone package was not part of
the library.
After manually adding it and rezipping the library I ran into another
missing module, this time it was missing backend_agg

Traceback (most recent call last):
  File "gcToCsv.py", line 5, in ?
  File "plot_output.pyc", line 1, in ?
  File "pylab.pyc", line 1, in ?
  File "matplotlib\pylab.pyc", line 195, in ?
  File "matplotlib\backends\__init__.pyc", line 20, in ?
ImportError: No module named backend_agg

I added that module and then saw that it was missing pyparsing
Traceback (most recent call last):
  File "gcToCsv.py", line 5, in ?
  File "plot_output.pyc", line 1, in ?
  File "pylab.pyc", line 1, in ?
  File "matplotlib\pylab.pyc", line 195, in ?
  File "C:\PYTHON23\Lib\site-packages\matplotlib\backends\__init__.py",
line 20,
 in ?
globals(),locals(),[backend_name])
  File
"C:\PYTHON23\Lib\site-packages\matplotlib\backends\backend_agg.py",
line
85, in ?
from matplotlib.mathtext import math_parse_s_ft2font
  File "C:\PYTHON23\Lib\site-packages\matplotlib\mathtext.py", line
140, in ?
from matplotlib.pyparsing import Literal, Word, OneOrMore,
ZeroOrMore, \
ImportError: No module named pyparsing

After that I stopped adding modules as I figured the problem was more
involved than just missing 1 or 2 modules.

My app just takes a set of data and plots it using the library. It does
not use matplotlib date functionality explicitly, it converts a list of
datatimes to a list of elapsed times (numbers of seconds) and plots
data against these floats.

The setup.py file I used was the one in the matplotlib documentation. I
then added the opt line to try and force the inclusion of that package.


I am relatively new to Python programming coming most recently from a
Java programming background, and was wondering why python does not have
the concept of a python archive much like a "jar" file in Java.
That would make all of these problems fairly trivial, inclusion of
dependant libraries would just be a matter of having the appropriate
"Python ARchive in a directory in the PYTHON_PATH so that it could be
loaded.

Thanks for any help on resolving my py2exe problems.

Scott Snyder

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


Re: OS X and Tkinter

2005-03-17 Thread scott
Mike Tuller wrote:
I have looked everywhere on the net, and can't figure out how to  
configure python so that Tkinter will work with it. Any help would be  
appreciated.
The following worked for me with OSX version 10.3 and the default python 
 2.3:

http://www.pythonmac.org/wiki/FAQ#head-8838d40da5d563166ca8b13cfb71cd2e856e81e3
"
5.5 How do I install Tkinter? How do I get IDLE to work?
Here are the steps for installing Tkinter:
	• 	 Download and install TclTkAqua
	• 	 Download and install the MacPythonPantherAddons if you are using 
the version of Python 2.3 included with OS X 10.3
	• 	 Open PackageManager, it is located in /Applications/MacPython-2.3
	• 	 Install _tkinter

You may then use Tkinter based applications such as IDLE, which should 
also be available from PackageManager. Note that if you are running any 
sort of GUI application from Terminal, you must use "pythonw" not 
"python" to launch the script.

 If the PackageManager complains that it cannot open a certain URL at 
www.python.org, choose "Open URL" from the "File" menu and open 
http://www.python.org/packman/version-0.3/darwin-7.7.0-Power_Macintosh.plist 
instead of the standard URL.
"
--
http://mail.python.org/mailman/listinfo/python-list


EasyDialogs module problem with python 2.4.1

2005-04-18 Thread scott
First my setup:
I'm using the framework build of Python 2.4.1
( http://bob.pythonmac.org/archives/2005/03/31/macpython-241-installer/ )
on an ibook G4 running Mac OS 10.3.8.
I installed wxPython 2.5.5.1 ( Unicode runtime 2.5.5.1 for the Panther 
version of Macpython-OSX 2.4 )

( http://wxpython.org )
Now my problem:
EasyDialogs module
( http://www.python.org/doc/2.4.1/mac/module-EasyDialogs.html )
works with pyshell (interactive python program included with wxPython) 
but not with python launched at the terminal:
ie:

---
PyShell 0.9.4 - The Flakiest Python Shell
Sponsored by Orbtech - Your source for Python programming expertise.
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import EasyDialogs
>>>EasyDialogs.Message('hi')
--
http://mail.python.org/mailman/listinfo/python-list


Re: EasyDialogs module problem with python 2.4.1

2005-04-18 Thread scott
scott wrote:
First my setup:
I'm using the framework build of Python 2.4.1
( http://bob.pythonmac.org/archives/2005/03/31/macpython-241-installer/ )
on an ibook G4 running Mac OS 10.3.8.
I installed wxPython 2.5.5.1 ( Unicode runtime 2.5.5.1 for the Panther 
version of Macpython-OSX 2.4 )

( http://wxpython.org )
Now my problem:
EasyDialogs module
( http://www.python.org/doc/2.4.1/mac/module-EasyDialogs.html )
works with pyshell (interactive python program included with wxPython) 
but not with python launched at the terminal:
ie:

---
PyShell 0.9.4 - The Flakiest Python Shell
Sponsored by Orbtech - Your source for Python programming expertise.
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>>import EasyDialogs
 >>>EasyDialogs.Message('hi')
Sorry, the rest of the message:
At the terminal, EasyDialogs doesn't work:
----
Last login: Mon Apr 18 10:30:53 on console
Welcome to Darwin!
scott$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import EasyDialogs
>>> EasyDialogs.Message('hi')
Traceback (most recent call last):
  File "", line 1, in ?
  File 
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-mac/EasyDialogs.py", 
line 75, in Message
_interact()
  File 
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-mac/EasyDialogs.py", 
line 53, in _interact
AE.AEInteractWithUser(5000)
MacOS.Error: (-1713, 'no user interaction is allowed')
>>>

-
I want to use EasyDialogs as a user front end for some simple scripts 
and can't do that until this issue is resolved. Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Re: EasyDialogs module problem with python 2.4.1

2005-04-18 Thread scott
Martin v. Löwis wrote:
Try pythonw.
Thanks, that was it.
One more question, when I use the EasyDialogs module to, for example, 
display a message in a dialog box, the dialog box doesn't appear directly.
I need to switch to 'python' by clicking on it on the dock or 
alt-tabbing to 'python' in order to see the dialog box.

--
scott$ pythonw
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import EasyDialogs
>>> EasyDialogs.Message('hi')
(At this point the 'python' icon appears on the dock and starts jumping. 
The actual dialog box won't appear until I manually switch to python 
with alt-tab.)

---
This again is in contrast to using Pyshell, where the dialog box 
automagically appears without further user input upon entry of 
EasyDialogs.Message('hi').

Question:
Can I get this Pyshell behavior using python from the terminal?
--
http://mail.python.org/mailman/listinfo/python-list


Jython run scripts problem (2.2.0a0 on Mac OSX 10.3.8)

2005-04-21 Thread scott
I installed darwinports and did a "sudo port install jython"
-
scott$ which jython
/opt/local/bin/jython
-
Jython works in interactive mode as shown below:
-
pyprogs$ cd hotbits/
hotbits$ ls
flips50.py  jythoninstall.py randomX  randomflip.py
hotbits$ jython
Jython 2.2a0 on java1.4.2_05 (JIT: null)
>>> # Truly random (radioactive decay triggered) coin flip
>>> from randomX import randomHotBits
>>> r = randomHotBits()
>>> if r.nextByte() < 0:
... print 'tails'
... else:
... print 'heads'
...
tails
--
Jython *doesn't* work if I save the above as a script and try to run it. 
It refuses to run the script and simply starts up in interactive mode:

---
hotbits$ jython randomflip.py
Jython 2.2a0 on java1.4.2_05 (JIT: null)
>>>
---
Question:
How can I run scripts as expected (outside interactive mode)?
Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2015-06-19 Thread Scott
We've been using a simple container implementation of a mathematical relation 
(https://simple.wikipedia.org/wiki/Relation_(mathematics)) (i.e. an invertible 
M:M mapping) for some time.
We've been waiting for many years (decades actually) to have this concept 
incorporated as a standard container in one of the modern programming languages 
so we could swap our code with a language-standard container. To further these 
efforts, we have decided to initiate a conversation with the python community 
on adding a relation as a standard Python container package. 

Briefly the uses of a relation are:

- quickly finding the values/range associated with keys/domain (e.g. 
*inversion*)
- maintaining a unique relationship between keys and values,(e.g. *isomorphism* 
or *aliasing*)
- using keys to categorize (one-to-many) values (e.g. *partitioning*)
- associating two sets in an arbitrary/bipartite manner (e.g. *tagging*)

Below is a link to an implementation, including an ipython notebook with light 
exposition and some canonical examples. We'll also be presenting a poster at 
SciPy 2015. Let us know if this, or something like it, seems like a worthwhile 
addition to the standard Python distribution.

Thank you,

Scott James, James Larkin

scott.ja...@noblis.org 
james.lar...@noblis.org


https://github.com/scott-howard-james/relate -- 
https://mail.python.org/mailman/listinfo/python-list


Relation: a new standard (PEP) container?

2015-06-19 Thread Scott
We've been using a simple container implementation of a mathematical relation 
(https://simple.wikipedia.org/wiki/Relation_(mathematics)) (i.e. an invertible 
M:M mapping) for some time.
We've been waiting for many years (decades actually) to have this concept 
incorporated as a standard container in one of the modern programming languages 
so we could swap our code with a language-standard container. To further these 
efforts, we have decided to initiate a conversation with the python community 
on adding a relation as a standard Python container package. 

Briefly the uses of a relation are:

- quickly finding the values/range associated with keys/domain (e.g. 
*inversion*)
- maintaining a unique relationship between keys and values,(e.g. *isomorphism* 
or *aliasing*)
- using keys to categorize (one-to-many) values (e.g. *partitioning*)
- associating two sets in an arbitrary/bipartite manner (e.g. *tagging*)

Below is a link to an implementation, including an ipython notebook with light 
exposition and some canonical examples. We'll also be presenting a poster at 
SciPy 2015. Let us know if this, or something like it, seems like a worthwhile 
addition to the standard Python distribution.

Thank you,

Scott James, James Larkin

scott.ja...@noblis.org 
james.lar...@noblis.org


https://github.com/scott-howard-james/relate 


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


Passing a Cookie with httplib

2006-06-28 Thread scott
Hello,

>From a shell script, I have used /usr/bin/curl to access a web site
and pass a cookie (as required by the site). But, I can't seem to
accomplish this task with Python.  I would like to use the httplib
module to do this.  Any thoughts on this subject?  I would like to
hard code the cookie in the code so it works every time:   

i.e. cookie = 'auth=buster%3A12345678901234567890exZ9rzMqgtxa5A'.  

The question is - how do I pass it with httplib?  Here is what I have
so far:


# Import external modules
import sys
import httplib

# Define our site and path
WP_SERVER="www.foo.com"
WP_PATH='/somedir/confirmquery?value=%s' 
try:
# Grab the command line argument
uservalue = sys.argv[1]
# Use the httplib module and connect
conn=httplib.HTTPConnection(WP_SERVER)
conn.request('GET',WP_PATH % uservalue)
response=conn.getresponse()
data=response.read()
conn.close()
print data
except:
print "Some stupid error occurred"
sys.exit(1)


Any help would be greatly appreciated,

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


Re: Passing a Cookie with httplib

2006-06-29 Thread scott
On Thu, 29 Jun 2006 21:42:50 +1200, Lawrence D'Oliveiro
<[EMAIL PROTECTED]> wrote:

>According to <http://docs.python.org/lib/httpconnection-objects.html>, 
>you can pass additional "body" and "headers" args to 
>HTTPConnection.request. How about trying something like this in place of 
>the last line above:
>
>Headers = {"Cookie" : 
>"auth=buster%3A12345678901234567890exZ9rzMqgtxa5A"}
>conn.request('GET',WP_PATH % uservalue, None, Headers)

Perfect!  Thanks so much.  I appreciate your help. I looked through
the docs before, but didn't spot this nugget because I was focused on
searching for the text "cookie".  Obviously, it pays to read... :-) 

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


Re: Passing a Cookie with httplib

2006-06-29 Thread scott
On Wed, 28 Jun 2006 20:21:37 -, Grant Edwards <[EMAIL PROTECTED]>
wrote:

>On 2006-06-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>> From a shell script, I have used /usr/bin/curl to access a web site
>> and pass a cookie
>
>I use ClientCookie for that.
>
>http://wwwsearch.sourceforge.net/ClientCookie/

Thanks Grant.  I'll take a look at this solution.

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


Newbie XML SAX Parsing: How do I ignore an invalid token?

2007-01-05 Thread scott
I've got an XML feed from a vendor that is not well-formed, and having
them change it is not an option.  I'm trying to figure out how to
create an error-handler that will ignore the invalid token and continue
on.

The file is large, so I'd prefer not to put it all in memory or save it
off and strip out the bad characters before I parse it.

I've included one of the problematic characters in a small XML snippet
below.

I'm new to Python, and I don't know how to accomplish this. Any help is
greatly appreciated!

-

Here is my code:

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

class ErrorHandler:
def __init__(self, parser):
self.parser = parser
def warning(self, msg):
print '*** (ErrorHandler.warning) msg:', msg
def error(self, msg):
print '*** (ErrorHandler.error) msg:', msg
def fatalError(self, msg):
print msg

class ContentHandler(ContentHandler):
def __init__ (self):
pass
def startElement(self, name, attrs):
pass
def characters (self, ch):
pass
def endElement(self, name):
pass

xmlstr = """

  
Tampa
A great city  and place to live
  
  
Clearwater
Beautiful beaches
  

"""
parser = make_parser()
curHandler = ContentHandler()
errorHandler = ErrorHandler(parser)
parser.setContentHandler(curHandler)
parser.setErrorHandler(errorHandler)
parser.parse(StringIO.StringIO(xmlstr))

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


Re: Newbie XML SAX Parsing: How do I ignore an invalid token?

2007-01-05 Thread scott
My original posting has a funky line break character (it appears as an
ascii square) that blows up my program, but it may or may not show up
when you view my message.

I was afraid to use element tree, since my xml files can be very long,
and I was concerned about using memory structures to hold all the data.
It is my understanding that SAX reads the file line by line?

Is there a way to account for the invalid token in the error handler? I
don't mind parsing out the bad characters on a case-by-case basis. The
weather data I am ingesting only seems to have this line break
character that the parser doesn't like.

Thanks!

Scott

Chris Lambacher wrote:
> What exactly is invalid about the XML fragment you provided?
> It seems to parse correctly with ElementTree:
> >>> from xml.etree import ElementTree as ET
> >>> e =  ET.fromstring("""
> ... 
> ...   
> ... Tampa
> ... A great city ^^ and place to live
> ...   
> ...   
> ... Clearwater
> ... Beautiful beaches
> ...   
> ... 
> ... """)
> >>> print ET.tostring(e)
> 
>   
> Tampa
> A great city ^^ and place to live
>   
>   
> Clearwater
> Beautiful beaches
>   
> 
> >>>
>
> Do you have invalid characters? unclosed tags?  The solution to each of these
> problems is different.  More info will solicit better solutions.
>
> -Chris
>
> On Fri, Jan 05, 2007 at 01:50:18PM -0800, [EMAIL PROTECTED] wrote:
> > I've got an XML feed from a vendor that is not well-formed, and having
> > them change it is not an option.  I'm trying to figure out how to
> > create an error-handler that will ignore the invalid token and continue
> > on.
> >
> > The file is large, so I'd prefer not to put it all in memory or save it
> > off and strip out the bad characters before I parse it.
> >
> > I've included one of the problematic characters in a small XML snippet
> > below.
> >
> > I'm new to Python, and I don't know how to accomplish this. Any help is
> > greatly appreciated!
> >
> > -
> >
> > Here is my code:
> >
> > from xml.sax import make_parser
> > from xml.sax.handler import ContentHandler
> > import StringIO
> >
> > class ErrorHandler:
> > def __init__(self, parser):
> > self.parser = parser
> > def warning(self, msg):
> > print '*** (ErrorHandler.warning) msg:', msg
> > def error(self, msg):
> > print '*** (ErrorHandler.error) msg:', msg
> > def fatalError(self, msg):
> > print msg
> >
> > class ContentHandler(ContentHandler):
> > def __init__ (self):
> > pass
> > def startElement(self, name, attrs):
> > pass
> > def characters (self, ch):
> > pass
> > def endElement(self, name):
> > pass
> >
> > xmlstr = """
> > 
> >   
> > Tampa
> > A great city  and place to live
> >   
> >   
> > Clearwater
> > Beautiful beaches
> >   
> > 
> > """
> > parser = make_parser()
> > curHandler = ContentHandler()
> > errorHandler = ErrorHandler(parser)
> > parser.setContentHandler(curHandler)
> > parser.setErrorHandler(errorHandler)
> > parser.parse(StringIO.StringIO(xmlstr))
> > 
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list

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


Re: Newbie XML SAX Parsing: How do I ignore an invalid token?

2007-01-07 Thread scott
Thanks, I'll work with the file on the file system, then parse it with
SAX.

Is there a Pythonic way to read the file and identify any illegal XML
characters so I can strip them out? this would keep my program more
flexible - if the vendor is going to allow one illegal character in
their document, there's no way of knowing if another one will pop up
later.

Thanks!


Martin v. Löwis wrote:
> [EMAIL PROTECTED] schrieb:
> > My original posting has a funky line break character (it appears as an
> > ascii square) that blows up my program, but it may or may not show up
> > when you view my message.
>
> Looking at your document, it seems that this "funky line break
> character" is character \x1E, which, in latin-1, means "record
> separator". It's indeed ill-formed to use it in XML.
>
> > Is there a way to account for the invalid token in the error handler?
>
> Not with a standard XML parser, no. The error you describe is a "fatal
> error", and that's not something parsing can recover from. I recommend
> that you filter this character out before passing it to the XML parser.
> You can use the IncrementalParser interface to do so.
> 
> Regards,
> Martin

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

ezPyCrypto confusion

2005-05-11 Thread scott
I am experimenting with ezPyCrypto
( http://www.freenet.org.nz/ezPyCrypto/ ).
Having difficulty making the key portable (ie put in a file). I don't 
get an error message, I just recover a message string that is empty 
instead of one that contains my message.

The code is below with a few extra print statements and comments that 
hopefully make my problem clearer. Any help in getting it to work as 
expected is appreciated. System is Mac OS 10.3 / Python 2.4.1 framework.

START PROGRAM

import ezPyCrypto

msg = 'Meeting delayed 30 hours'
print msg
print ''
k = ezPyCrypto.key(512)
cipher = k.encStringToAscii(msg)
print cipher
msg_back = k.decStringFromAscii(cipher)
print msg_back
print ''

# So far so good. encrypted and decrypted as expected.
# Now try to put the key in a file for transport on eg a USB drive.

key_as_string = k.exportKey()
print key_as_string
f = open('/Users/scott/pyprogs/the_key.txt', 'w')
f.write(key_as_string)
f.close()

# Now get string representation of k (the key object above) and use it
# to create a key object (ke) that should decode the original cipher

f=open('/Users/scott/pyprogs/the_key.txt', 'r')
x = f.read()
ke = ezPyCrypto.key(x)
print ke# Key object exists (good)
recovered_msg = ke.decString(cipher)
print type(recovered_msg)  # A message string is returned  (good)
print len(recovered_msg)   # The string is EMPTY! (not good)
print recovered_msg# No message returned (not good)
f.close()

END PROGRAM---

RUN PROGRAM--

scott$ python testezPyCrypto10.py
Meeting delayed 30 hours


5AAoVQNSU0FxAChjQ3J5cHRvLlB1YmxpY0tleS5SU0EKUlNBb2JqCnEBb3ECfXEEKFUBZXEFTDY1
NTM3TApVAW5xBkw3MDg1MTU0ODQ3Nzg2Mzg1NzA3ODYxMzQ0NDcwNDQ3MDkzMTQ0NzkxNDIyMzAy
MDMwMjQxMTcxNjY2NzQ3MjQ3Njc0MTAxMTYwNjA4OTA0ODUxMzgxMDkyMjkwNjk5OTM3MTUwMTc0
Njc3MzI5NjY3NjQzOTUzNjQzMDQ4MTEwMTYwMTMyMDE3Nzk4MTcxOTYzOTkwMTY0MzIxTAp1YnRx
By5DAAFAAB0nHmncdr+reFXlH3sqlTD3sGzljukoy7bD0CqTIx0G/wUBQikdDz/jUPG1lJeDpc3V
yW5alZnazsunbv9ck6RDAAFAAINJBPMc/j8FQznrDhrd5bIjsEIdYgL8Mhuyz4duDF2usmzKG+B0
zjuatNSSgYr6D3NsBnGc8kgcZFFsSldWql5DAAFAABuHpHTspBrEF4I9RWBMFdaw8bpAAaEx69w5
wAu5jx1PiPLHY+8VVWshIaIjKjTPnWuD1OmSIr17k0R5XTNoLakIKBLNld6+SaoIb1AIRsYowggI
y/BY6VP0e70A


Meeting delayed 30 hours


KEkwMApOVeQoVQNSU0FxAChjQ3J5cHRvLlB1YmxpY0tleS5SU0EKUlNBb2JqCnEBb3ECfXEEKFUB
ZXEFTDY1NTM3TApVAW5xBkw3MDg1MTU0ODQ3Nzg2Mzg1NzA3ODYxMzQ0NDcwNDQ3MDkzMTQ0Nzkx
NDIyMzAyMDMwMjQxMTcxNjY2NzQ3MjQ3Njc0MTAxMTYwNjA4OTA0ODUxMzgxMDkyMjkwNjk5OTM3
MTUwMTc0Njc3MzI5NjY3NjQzOTUzNjQzMDQ4MTEwMTYwMTMyMDE3Nzk4MTcxOTYzOTkwMTY0MzIx
TAp1YnRxBy5xAHRxAS4=




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


Change Geany Syntax Highlighting

2007-06-26 Thread Scott
Hi,

 I think I may have finally found a IDE/text editor that I like,
but, it still haves one problem.  Geany haves syntax highlighting, but
it is not very good for Python.  It only seems to have a couple
different colours.  One for text and another for modules/classes/
functions.  Is it possible to change the syntax highlighting for
Python, so it highlights more and uses more different colours?  I
really liked the syntax highlighting for Python in kwrite/kate, but
did not like the bugs.

Your friend,
Scott

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


Reversing a string

2007-06-27 Thread Scott
Yeah I know strings == immutable, but question 1 in section 7.14 of "How to 
think like a computer Scientist" has me trying to reverse one.

I've come up with two things, one works almost like it should except that 
every traversal thru the string I've gotten it to repeat the "list" again. 
This is what it looks like:

[code]
>>>mylist = []
>>>def rev(x):
for char in x:
mylist.append(char)
mylist.reverse()
print mylist
[/code]

And the output that sorta works like it should, but threw a curveball, at me 
looks like this:
>>> rev("this is just a test")
['t']
['h', 't']
['i', 't', 'h']
['s', 'h', 't', 'i']
[' ', 'i', 't', 'h', 's']
['i', 's', 'h', 't', 'i', ' ']
['s', ' ', 'i', 't', 'h', 's', 'i']
[' ', 'i', 's', 'h', 't', 'i', ' ', 's']
['j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ']
['u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j']
['s', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u']
['t', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's']
[' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 't']
['a', 't', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's', ' ']
[' ', ' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 't', 'a']
['t', 'a', 't', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's', ' ', 
' ']
['e', ' ', ' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 't', 
'a', 't']
['s', 't', 'a', 't', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's', 
' ', ' ', 'e']
['t', 'e', ' ', ' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 
't', 'a', 't', 's']


So I figured maybe make it a generator (I'm not TO familiar with generators 
yet so don't laugh) which changed my code just a slight bit:

[code]
>>>mylist = []
>>>def rev(x):
for char in x:
mylist.append(char)
mylist.reverse()
yield mylist
[/code]

But even that threw me a curveball:
>>> rev("this is just a test")


So how on earth would be the best way to: Write a function that takes a 
string as an argument and outputs the letters backward, one per line.

It should look like the first char of every list in the top "working" code.

Any help woould be greatly apreciated, and a little bit of explaination as 
to why you did it the way you did would be more helpful than just the code.

Thanks in advance 


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


Python compared to other language

2007-05-18 Thread scott
Hi all,

I have been looking at the various programming languages available.  I 
have programed in Basic since I was a teenager and I also have a basic 
understanding of C, but I want something better.

Can anybody tell me the benefits and weaknesses of using Python?

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compared to other language

2007-05-18 Thread scott
Thank you everyone for your help.  I will make sure to check the 
archives, something I should have done first :)

-- 
Your friend,
Scott

Sent to you from a 100% Linux computer using Kubuntu Version 7.04 
(Feisty Fawn)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Bulk] Re: Python compared to other language

2007-05-19 Thread scott
Michael Torrie wrote:

> I think the original poster will find Python, and may wxPython,
> satisfies the bulk of his development needs.
True, I like how Python is a general language that can be used for many 
different purposes and hope to learn wxPython as well.  I have read 
through the archives and found some good suggestions for books/tutorials.

-- 
Your friend,
Scott

Sent to you from a 100% Linux computer using Kubuntu Version 7.04 
(Feisty Fawn)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A few questions

2007-05-24 Thread scott
[EMAIL PROTECTED] wrote:
> Just wanted to send a quick "Thank You!" to everyone who helped answer my 
> questions.  This 
> list is awesome!!
I'm finding the same, this list is amazing.  There is a more welcome 
feeling than the C or C++ list I have seen.

> I'm currently reading "How to Think Like a Computer Scientist" (thanks 
> Basilisk96)
Me too, it is an amazing book and I am loving Python much better than C. 
  I would just like to find some answers to the exercises to make sure 
I'm doing them correctly.

> I still want to take a look at "Dive into Python" as well as the other books 
> you all 
> mentioned.
I put "Dive into Python" on my palm.  Is it a good 2nd book to go through?

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-- 
http://mail.python.org/mailman/listinfo/python-list


threads, mutual exclusion, and lists

2007-08-15 Thread Scott
I have two threads that share a python list. One thread adds to the
list with append(), the other thread removes items with pop().

My question is -- are python list operations atomic? If they are not,
then I assume I need to put some mutual exclusion around the append()
and pop() calls ?

Thanks,
Scott

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


Newbie Question about sequence multiplication

2007-04-04 Thread Scott
Alright, so I've been trying to teach myself Python which, when compared to
my attempt to learn C++, is going pretty well.
But I've come across an issue that I can't figure out, so I figured I'd ask
the pro's.

Now it looks pretty weird in this format but it was copied exactly from IDLE

*code follows***

#What this program is suppose to do is print a sentence centered in a box

sentence = raw_input('Sentence: ')

screen_width = 80
text_width = len(sentence)
box_width = text_width + 6
left_margin = (screen_width - box_width) // 2

print
print ' ' * left_margin + '+'   + '-' * (box_width-2)  +  '+'
print ' ' * left_margin + '|  ' + ' ' * text_width + ' |'
print ' ' * left_margin + '|  ' + ' '   sentence   + ' |'
print ' ' * left_margin + '|  ' + ' ' * text_width + ' |'
print ' ' * left_margin + '+'   + '-' * (box_width-2)  + ' |'
print

end code

Now that, even though copied straight from "Beginning Python: From Novice to
Professional", returns :
There's an error in your program: invalid syntax

with the word sentence highlighted (not the sentence when I'm defining the
name, the one in..uhmthe body of the code)


Now if i put * before sentence as it is with the rest of the variables, it
actually gets to the point where it asks me for the sentence, but after
inputting my sentence I receive:
Traceback (most recent call last):
  File "D:/Programming/Python/sequence string multiplication example", line
16, in 
print ' ' * left_margin + '|  ' + ' ' * sentence   + ' |'
TypeError: can't multiply sequence by non-int of type 'str'

Why can't I get it to do what it's supposed to do? What am I
missing/misunderstanding?
Very simply all its supposed to do is something like this (now bear with me
formating might distort this a bit lol)
++
||
|  Like This|
||
++

Any help would be greatly appreciated


-Scott




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


Re: Newbie Question about sequence multiplication

2007-04-06 Thread Scott
Thanks to everyone that respondedI would never have figured that out.

7stud,
Your suggestion is being considered lol, as there are a lot more bits of 
code in that book that I can't get running correctly.
Any other books you'd, or anyone for that matter, would recommend as 
required reading?  Free would be very very (read very) good, as you've 
already said the one I have isn't very viable and it cost me $50. 
Basically, what I'm saying is that if I go and spend another $50+ my wife is 
going to make it very hard to learn Python; after all, how much can I learn 
with a size 5 down my throat? lol


Now when suggesting books, keep in mind that, that while I'm new to Python 
(and programming in general)  I'm able to grasp difficult concepts as long 
as I have enough detail as to why it is the way it is.  For instance I'm, by 
experience and nature, a computer technician and communications specialist. 
I've studied,  everything from childrens walkie talkie to deep space 
satalittes back to how computers talk (which is why I'm here now trying to 
learn the language of computers).  And all that just because I have a 
unquenchable desire to know.  SO, with that all said, the more details the 
better. If you have a book with 4 chapters on functions..I want to read 
it.

Any help would be greatly appreciated.  As I've said, this is something that 
I feel I have to know.



"7stud" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Apr 4, 4:48 pm, "John Machin"
> I suggest you get another book.  I am currently reading that book, and
> unless you are an experienced programmer that can detect all the
> mistakes, and you have another book like "Python in a Nutshell" to
> fill in all the gaps, I don't think you can learn python from that
> book.
>
> I recently looked at Learning Python in the bookstore, and it seems a
> lot better.  Unfortunately, it doesn't reflect the major changes in
> python over the last couple of years, but I would still recommend it
> over Beginning Python: From Novice to Professional.
>
>
> 


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


pop() clarification

2007-04-11 Thread Scott
As said before I'm new to programming, and I need in depth explaination to 
understand everything the way I want to know it, call it a personality quirk 
;p.

With pop() you remove the last element of a list and return its value:

Now I know list is a bad name, but for the sake of arguement lets assume its 
not a built in sequence>

>>>list = ['this', 'is', 'an', 'example']
>>>list.pop()
'example'
>>>list
['this', 'is', 'an']

I understand all that.  What I don't understand is why all the documentation 
I see says, "When removing a specific element from a list using pop() it 
must be in this format: list.pop([i]).
At first I took that to mean that list.pop(i) would return some type of 
error, but it doesn't.
I can't find any documentation saying that this rule that I keep reading 
about (again list.pop([i]) ) is the only format to use when removing a 
specific element because..with the explaination to follow.

Now I'm not stupid enough to believe that I'm the first to try:
>>>list = ['this', 'is', 'an', 'example']
>>>list.pop(1)
and have it return the desired effect of:
'is'
>>>list
['this', 'an', 'example']


I guess simplistically all I'm asking is:  Is this just a community agreed 
upon rule for readability purposes? or Is it a rule that's in place for a 
reason I'll learn later on?  Please keep in mind my intro sentence to this 
post.  I would like a very detailed explaination, or at least a link to a 
very detailed expression.  ONLYof courseif the explaination isn't, 
well it just is because we all agreed to use it that way.  That explaination 
I'll understand and except, but with a bit of dissatisfaction. 


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


Re: Hellow World:)

2007-04-11 Thread Scott
The author of that book is qouted as saying:
''Note: My more recent book, Beginning Python is an expanded and revised 
version of this book.''

That qoute can be found at http://hetland.org/writing/practical-python/
However, from my personal experience some of the codes in beginning python 
have some errors and without a decent foundation in programming can lead to 
very frustrated attempts at understanding a topic, but the source for all 
code examples can be found online at 
http://hetland.org/writing/beginning-python/

As someone thats new to programming myself visit http://diveintopython.org/ 
its a book thats written by the same guy (I believe), and so far its helped 
me tremendously in conjuction with beginning python and (now dont laugh) 
python for dummies.  That book was suggested to me when I asked basically 
the same thing you are asking.


"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> En Thu, 29 Mar 2007 16:19:24 -0300, void pointer 
> <[EMAIL PROTECTED]> escribió:
>
>> Hi All ..I am looking for PDF version of " Practical Python"  and a 
>> language to stick to .Should I find that book ,I wil lconsder  this 
>> Python :)


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

Question About Creating Lists

2007-04-12 Thread Scott
I'm sorry if most of my question's seem "petty", but as I've said before, I 
need to know the petty just because I need to know.

This question is more along the lines of just having you guys either agree 
or disgree with me, and if disagreeing to give the reasoning behind it, to 
further my understanding of lists.

Am I safe in assuming that if the list your building contains number's it 
will be written as follows:

>>>my_list = [1, 2, 3, 4, 5]

But the minute you throw in something that's not a number it has to be 
written as:

>>>my_list = [1, 2, 3, 4, 'five']
>>> my_list
[1, 2, 3, 4, 'five']

Unless five was defined, then it could be written as:

>>>five = 5
>>>my_list = [1, 2, 3, 4, five]
>>> my_list
[1, 2, 3, 4, 5]


Is this the correct way of thinking? Or am I, by thinking this is the case, 
crippling myself in my potential as a programmer 


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


Lists and Tuples and Much More

2007-04-12 Thread Scott
I'm going to start grouping all my questions in one post as this is my 
second today, and sorta makes me feel dumb to keep having to bother you all 
with trivial questions. I'll just seperate my questions with:
---
Now onto the issue:
List's and Tuple's
I don't see the distinction between the two.  I mean, I understand that a 
list is mutable and a tuple is immutable.
The thing that I dont understand about them is what, besides that, seperates 
the two.  I did a little experimentation to try to understand it better, but 
only confused myelf more.

A list looks like this:

>>>my_list = [1, 2, 3, 4, 5, 6]

and a tuple looks like this:

>>>my_tuple = (1, 2, 3, 4, 5, 6)

Now you can add to a list, but not a tuple so:

>>>my_list.append(my_tuple)  #or extend for that matter right?
[1, 2, 3, 4, 5, 6, (1, 2, 3, 4, 5, 6)]

Is that pretty much accurate? And which is better on resourcesI'm 
guessing a tuple seeing as it doesn't change.

And the last example brings up another question.  What's the deal with a 
tupple that has a list in it such as:

>>>my_tupple = (1, 2, 3, 4, 5, [6, 7, 8, 9])

Now I read somewhere that you could change the list inside that tupple.  But 
I can't find any documentation that describes HOW to do it.  The only things 
I CAN find on the subject say, "Don't do it because its more trouble than 
it's worth."  But that doesn't matter to me, because I want to know 
everything.
-

Now there comes append.  I read everywhere that append only add's 1 element 
to the end of your list.  But if you write:
>>> my_list = [1, 2, 3, 4, 5, 6]
>>> my_list.append([7, 8, 9, 10])
>>> my_list
[1, 2, 3, 4, 5, 6, [7, 8, 9, 10]]

Is that because list's, no matter what they contain, are counted as 1 
element?

And how would you sort the list that's in the list?  I guess that goes in 
conjunction with the section above, but still:
>>> my_list = [6, 4, 3, 5, 2, 1]
>>> my_list.append([7, 9, 8, 10])
>>> my_list.sort()
>>> my_list
[1, 2, 3, 4, 5, 6, [7, 9, 8, 10]]

This is, again, something I'm finding nothing on.
-

Maybe I'm just not looking in the right spots.  The only things I have as 
learning aids are: this newsgroup ;p, http://diveintopython.org, 
http://python.org/, Beggining Python: From Novice to Professional,  and (now 
don't laugh) Python for Dummies.


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


Re: Question About Creating Lists

2007-04-12 Thread Scott


> Please forgo the psychological self analysis from your future posts.

Unfortunately I can't, that's how I am, love it or leave it.  But if your 
going to be condescending about it, please leave your future replies in your 
outbox.  Now don't take that as I don't appreciate your reply.  I just don't 
appreciate the tone of that statement. I wouldn't say something about your 
pseudonym possibly making up for some personal deficiency only because it 
wouldn't be right. Email etiquette is a beautiful thing.

And I'm sorry if you didn't mean it that way, but that's the way it read.

> I don't think your question has anything to do with lists.  Maybe this
> will help: there is a distinction between what are called "literals"
> and "variables".

My question was in fact about lists and their proper "syntax" (I'm guessing 
that's the right word). Basically all I was asking was if I had the idea 
down or not, which was meant to be implied when I wrote: Am I safe in 
assuming

Maybe I didn't write it the exact way to get the response I needed, and if 
it read differently I'm sorry. But that's all I was asking. 


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


Re: Lists and Tuples and Much More

2007-04-13 Thread Scott

"7stud" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> Yes. Tuples are immutable - once created, they can't change.
>
> Just to explain that statement a little better.  If you do this:
>
>
> t = (1, 2, ["red", "white"])
> t[2].append("purple")
> print t#(1, 2, ['red', 'white', 'purple'])
>
>
> It sure looks like t changed, and therefore t is NOT immutable--and
> the whole "tuples are immutable" mantra is a lie.  However, the list
> itself isn't actually stored inside t.  What's stored inside t is
> python's internal id for the list.  So suppose python gave the list
> the internal id: 10008.  The tuple really looks like this:
>
> t = (1, 2, <10008>)
>
> And no matter what you do to the list: append() to it, sort() it,
> etc., the list's id remains the same.  In that sense, the tuple is
> immutable because the id stored in the tuple never changes.
>
> In actuality, the numbers 1 and 2 aren't stored in the list either--
> python has internal id's for them too, so the tuple actually looks
> like this:
>
> t = (<56687>, <93413>, <10008>)
>   | ||
>   | ||
>   | ||
>   V VV
>   1 2["red", "white", "purple"]
>
>
> Because of that structure, you can create situations like this:
>
 lst = ["red", "white"]
 t1 = (1, 2, lst)
 t2 = (15, 16, lst)
 print t1
> (1, 2, ['red', 'white'])
 print t2
> (15, 16, ['red', 'white'])
 lst.append("purple")
 print lst
> ['red', 'white', 'purple']
 print t1
> (1, 2, ['red', 'white', 'purple'])
 print t2
> (15, 16, ['red', 'white', 'purple'])

>
> lst, t1, and t2 all refer to the same list, so when you change the
> list, they all "see" that change.  In other words, the names lst,
> t1[2], and t2[2] all were assigned the same python id for the original
> list ["red", "white"].  Since all those names refer to the same list,
> any of those names can be used to change the list.
*
This is exactly the type of explaination I'm looking for.  Thank you much!!! 


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


Re: Question About Creating Lists

2007-04-13 Thread Scott
> And that's a really sideways way to take a swipe at someone while 
> pretending to be too high-minded to do it (plus see James's comments about 
> other possible explanations). If you kiddies would take this fight out 
> into the playground perhaps the rest of the class can continue.

It wasn't meant as a swipe, it was an example of what he did turned around. 
There was no fight, at least on my end.  What happened was I was confronted 
something that I didn't appreciate it, and I made it known, just as most 
people would if it happened face to face.

> It *would* be helpful if you "just asked the question". You said in your 
> original post that "... I need to know the petty just because I need to 
> know", but that's an abuse of the word need unless you suffer from a quite 
> unusual psychological compulsion.

I see the point to getting to the point (lol). Most people don't worry about 
my ramblings, and I've found that if they aren't included I get a 1-2 line 
answer. That 1-2 line answer, while fine for most, just WILL not help me. It 
actually makes it worse. I have a compulsion for knowledge that pass' far 
beyond what most people would call healthy. So much so that I take 
medications I'm not about to list here. If I attempt to learn something and 
don't understand it, my entire mindset is taken over by my desire. I CAN NOT 
sleep, eat, or function "normally" until I KNOW even the mundane.  I hate 
using the following example, but it helps some people understand how my mind 
thinks.  Have you ever seen a crack addict walking down the street (or on 
tv) and their thoroughly searching the ground for the crack that they 
dropped (that they never really had)?  Take that and substitute crack for 
knowledge and you'll have me. SO now you see why I start my posts the way I 
do.

> To you. Get over it, this is Usenet. You will experience worse if you 
> stick at it long enough.

I've already come to this understanding just as most who frequent any type 
of "community" online, what with all the internet tough guys who frequent 
most forums. That's in no way a knock at 7stud just an observation of most 
troublemakers.  But just because we all know its there, doesn't make it 
acceptable, nor does it mean anyone should have to tolerate it just because 
they chose to hop online.  When someone makes it known a certain thing 
bothers them, the polite thing to do would be to stop. I bet if I TYPED IN 
CAPS LOCKS FOR EVERYTHING I WROTE, someone, if not everyone, would say 
something.  Its the same idea with what I did.

There are plenty of ways to stop this kind of treatment online, and if more 
people knew that all they had to do was make a call to thier ISP, or to the 
local police department with even just a pseudonym, that kind of treatment 
would become less acceptable. I deal with these types of reports every day 
at work.  Fines can be impossed no matter where the harrasser is, and 
depending on the context can actually involve jail time. Of course this 
actual issue is very petty, and all that is/should be needed, was my 
addressing the fact that it was not polite. That should of been the end of 
it, and it seems to have been.

Believe it or not the problem lies with the people getting harrased, not the 
harrasser.  They believe nothing will be done and so they don't try, and 
then they come to accept it.  How wrong they are. 


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


Re: Python 3 and my Mac (Leopard)

2008-12-27 Thread scott

Dan wrote:
Wanted to learn python, got Mark Summerfield's new book "Programming in 
Python 3".  Having a hard time getting python 3 and IDLE working on my 
Mac with Leopard.  The mac "resources" on the python.org site seem a bit 
out of date, and don't really mention python 3.  Are there any resources 
out there?  Is the python community just not interested in Macs?  I've 
tried googling and the usual search strategies.  Any help would be 
appreciated.


DAN



Activestate has a Python 3.0 distribution for 8 or 9 platforms including 
Mac OS X:

http://www.activestate.com/Products/activepython/python3.mhtml
IDLE works well here on Leopard (calltips etc) and they have bundled 
documentation in Apple help format.


Note:
I installed ActiveTcl prior to installing Python 3.0:
http://www.activestate.com/Products/activetcl/index.mhtml
I'm not sure if this was necessary for proper IDLE function or not. Both 
ActivePython 3.0 and ActiveTcl installs were painless.

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


Remote control of firefox (mozilla) from a python program

2008-11-10 Thread Scott
I have a requirement to control a firefox web browser from an external
python program.  The python program running under linux from a command
shell needs to first find all open firefox web browser windows read
the URL currently displayed in each web browser and if the URL matches
a particular regular expression it needs to get/set form fields
displayed in the web browser.  Basically I need something like Windows
COM and Internet Explorer where you can use COM to get/set form
elements in the web page as well as post the web page.  Does xpcom
provide this?  Is there some other method?  Mozilla has an xpcom
interface but I am not sure it is available to a python program
running in a different process as my scenario describes.  At some
point I will need this python program to run under Mac OS X but for
now I need something running under Linux.
--
http://mail.python.org/mailman/listinfo/python-list


passing a variable argument list to a function

2008-08-12 Thread Scott
I'm trying to write a function that accepts a variable number of
arguments and passes those arguments to another function. Here is an
example:

def foo(*args):
print "I'm going to call bar with the arguments", args
bar(args)

This doesn't do quite what I want. For example, if I call foo(1,2,3,4)
then it calls bar((1,2,3,4)). It passes a tuple rather than expanding
the argument list back out.

I suspect there's a simple bit of syntax that I'm missing -- can
anyone give me a hand?

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


getting full exception information from an xmlrpc server

2008-08-13 Thread Scott
I'm debugging an xmlrpc client/server application. Often when an
exception occurs in the server, I receive only a very short error
message on the client. For example:

xmlrpclib.Fault: :">

Presumably this is because xmlrpclib on the server is catching the
exception, and only sending the exception name to the client, not the
server's stack trace.

What I would like is the full stack trace of what went wrong on the
server (i.e. the junk python usually dumps to the console when an
exception occurs). I don't care which side I see the dump on (client
or server), but I need to see the whole trace so I can figure out what
the problem is. Is there an easy way to do this?

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


Re: passing a variable argument list to a function

2008-08-13 Thread Scott
> Yeah. It's so easy and obvious that you are going to bang your head
> against the wall. :) The single star does not only collect all arguments
> in a function definition. It also expands a sequence as arguments.

Thanks Christian, that worked perfectly!

Scott

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


creating a similar object from an derived class

2008-09-03 Thread Scott
Let's say I have an object:

class foo():
   def create_another()
   return foo()

   def blah():
   x = self.create_another()
   ... do something with X

Now I create a inherited class of this object:

class bar(foo):
...

If I call bar.create_another(), it will return a foo() instead of a
bar(). This isn't what I want. I would like bar.create_another() to
create an instance for bar(). Obviously I can do this by overriding
create_another, i.e.

class bar(foo):
def create_another()
return bar()

However, is there a way for me to modify foo() so that it
automatically creates objects of the derived class, so that I don't
have to continue to redefine create_another() ?

For example, I tried the following:

def create_another()
return self.type()()

but it did not work.

Thanks,
Scott


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


mod_python and PHP sharing same session

2006-04-03 Thread Scott
I am trying to get a mod_python application to read an existing PHP
session.  I need some data that was set in the session by the PHP
application.  I am using the mod_python Session class but even when I
specify the session id that PHP uses the Sesssion(req, sid) call
returns a new session id.  The session file exists in /tmp as
mp_sess.dbm and I have verified that PHP is reading/writing it and from
what I have read mod_python will use the same file.  I have used the
PythonOption session DbmSession in the Apache configuration to force
this and specified the filename as well but to no avail.

Has anyone attermpted what I am trying to perform and if so a short
snippet of code or explanation of how to interface to PHP session via
mod_python would be great.  I am not an experiecne PHP users but have
used mod_python extensively.
Scott

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


Fundamental Function Question (beginner)

2010-01-11 Thread Scott
When creating a function is there any difference between putting
everything under the "def" or not?

Here I created a function called CscoPortNum to convert the network
port number field in a Cisco syslog string from a an ascii name back
into its numeric form if required. Does it matter at all that I
created the translation dictionary first and then started the def?

# def CscoPortNum(RulL)
# Accept a single ACL Rule as a List split into individual words and
# return Port number. Convert from Cisco syslog Port name if required
portfpth = "\\progra~1\\syslogd\\ACL_Logs\\Port-Translations.txt"
# Create dictionary of portnames to portnumbers
portD = {}
for prtnmS in open(portfpth):
prtnmS = prtnmS.rstrip()
spltprtL = prtnmS.split(" ")
portD[spltprtL[2]] = [spltprtL[1]]
def CscoPortNum(RulL):
if "eq" in RulL:# Is the Port listed?
if RulL[RulL.index("eq")+1][0].isdigit(): # Is it numeric?
#if re.search("\d", RulL[RulL.index("eq")+1][0]): # Is it
numeric?
portnum = RulL[RulL.index("eq")+1] # If numeric, use
as is.
else:
# If named, look up numeric translation
portnum = portD[RulL[RulL.index("eq")+1]]
portnum = str(portnum).strip("[]'")
else:  portnum = "noeq"
return portnum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fundamental Function Question (beginner)

2010-01-11 Thread Scott
On Jan 11, 1:50 pm, Phlip  wrote:
> MRAB wrote:
> > Scott wrote:
> >> for prtnmS in open(portfpth):
> >>     prtnmS = prtnmS.rstrip()
> > There's nothing wrong with building dicts or other lookup tables outside
> > a function in order to avoid re-creating them every time the function is
> > called.
>
> However, please consider writing complete, pronounceable names for variables.
> This looks like Fortran!

Thanks for the advice.
Scott
Chrmn, Scty fr th lmntn f vwls
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fundamental Function Question (beginner)

2010-01-11 Thread Scott
> There's nothing wrong with building dicts or other lookup tables outside
> a function in order to avoid re-creating them every time the function is
> called.

Brilliant! I didn't think of that. I guess I accidentally did it right
this time as I query that dictionary quite a few times from the
function.

Thanks MRAB and All!
-- 
http://mail.python.org/mailman/listinfo/python-list


Using String for new List name

2009-09-28 Thread Scott
I am new to Python but I have studied hard and written a fairly big
(to me) script/program. I have solved all of my problems by Googling
but this one has got me stumped.

I want to check a string for a substring and if it exists I want to
create a new, empty list using that substring as the name of the list.
For example:

Let's say file1 has line1 through line100 as the first word in each
line.

for X in open("file1"):
Do a test.
If true:
Y = re.split(" ", X)
Z = Y[0]  # This is a string, maybe it is "Line42"
Z = []  # This doesn't work, I want a new, empty
list created called Line42 not Z.

Is there any way to do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using String for new List name

2009-09-28 Thread Scott
Thank you fine folks for getting back with your answers!

So down the road I do dictname[line42].append("new stuff"). (or [var]
if I'm looping through the dict)

This is cool and should do the trick!

-Scott Freemire
disclosure - Ok, I'm new to *any* language. I've been teaching myself
for about 3 months with "Learning Python, 3rd Edition" and I think
it's going well! Of course I picked something way too complicated for
a first try. Thanks again!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using String for new List name

2009-09-28 Thread Scott

> That should actually be dictname["line42"].append("new stuff").  Notice
> the quotes around line42.
>
> Good luck!  Python is a fine language, I hope you like it.
>
> ~Ethan~

Doh. I sent it before my type, fail, fix cycle had taken place.
Got it.
Thanks again all!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using String for new List name

2009-09-28 Thread Scott
On Sep 28, 2:00 pm, Dave Angel  wrote:
> Scott wrote:
> > Thank you fine folks for getting back with your answers!
>
> > So down the road I do dictname[line42].append("new stuff"). (or [var]
> > if I'm looping through the dict)
>
> Nope, you still haven't gotten it.  Of course, I really don't know where
> you're going wrong, since you didn't use the same symbols as any of the
> responses you had gotten.
>
> I suspect that you meant dictname[] to be the dictionary that Duncan
> called values[].  On that assumption, in order to append, you'd want
> something like:
>
> values["line42"].append("new stuff")
>      or
> values[var].append("new stuff") if you happen to have a variable called
> var with a value of "line42".
>
> You will need to get a firm grasp on the distinctions between symbol
> names, literals, and values.  And although Python lets you blur these in
> some pretty bizarre ways, you haven't a chance of understanding those
> unless you learn how to play by the rules first.  I'd suggest your first
> goal should be to come up with better naming conventions.  And when
> asking questions here, try for more meaningful data than "Line42" to
> make your point.
>
> Suppose a text file called "customers.txt" has on each line a name and
> some data.  We want to initialize an (empty)  list for each of those
> customers, and refer to it by the customer's name.  At first glance we
> might seem to want to initialize a variable for each customer, but our
> program doesn't know any of the names ahead of time, so it's much better
> to have some form of collection. We choose a dictionary.
>
> transactions = {}
> with open("customers.txt") as infile:
>     for line in infile:
>         fields = line.split()
>         customername = fields[0]            #customer is first thing on
> the line
>         transactions[customername] = []       #this is where we'll put
> the transactions at some later point, for this customer
>
> Now, if our program happens to have a special case for a single
> customer, we might have in our program something like:
>
>     transactions["mayor"].append("boots")
>
> But more likely, we'll be in a loop, working through another file:
>
> .
>         for line in otherfile:
>                fields = line.split()
>                customername = fields[0]
>                transaction = fields[1]
>
> transactions[customername].append(transaction)                #append
> one transaction
>
> or interacting:
>       name = raw_input("Customer name")
>       trans = raw_input("transaction for that customer")
>       transactions[name].append(trans)

Dave,

I'm amazed at everyone's willingness to share and teach! I will sure
do the same once I have the experience.

I think that one of the problems here is that I tried to make my
initial question as bone simple as possible. When I first tried to
explain what I was doing I was getting up to 2 pages and I thought "I
bet these folks don't need to read my program. They probably just need
to know the one bit I'm looking for." So I deleted it all and reduced
it to the 10 line example that I posted.

It was then suggested that I eschew using regular expressions when not
required because I used Y = re.split(" ", X) in my example. In my
program it is actually aclLs = re.split("\s|:|/", aclS) which I think
requires a regex. I just didn't want anyone to waste their time
parsing the regex when it was not really germane to my actual
question.

The same applies to the suggestion for using meaningful variables. In
the above aclLs represents (to me) "access control list List-Split"
and aclS represents "access control list String." Again, I thought X
and Y, like foo and bar or spam and eggs would do for a simple
example.

Of course I then went and forgot the quotes around "line42" and really
looked confused. I was so excited to have an answer that I typed the
reply without thinking it through. Not good.

Don't worry though, I take no offense. I understand and welcome the
advice. I don't have anyone to work with and this post is my first
interaction with any person who knows programming and Python. I am but
a network engineer (Cisco, Lan/Wan, firewalls, security, monitoring
(this is the connection), etc.) who has never programmed. I will work
on clearer communications in future posts.

I'm happy for a chance to share what I am actually trying to
accomplish here.

I have a firewall with a static list of access-control-list (ACL)
rules (about 500 rules). I also have a directory with one wee

How to sort a list of strings on a substring

2009-10-05 Thread Scott
I create a list of logs called LogList. Here is a sample:

LogList =
["inbound tcp office 192.168.0.125 inside 10.1.0.91 88",
"inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
"inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
"inbound udp office 192.168.0.220 inside 10.1.0.13 53"]

I want to sort the list on index 3 of each string - the first IP
Address.

I only need strings with similar, first IP's to be together. I don't
need all of the IP's to be in order. For example:
either:
SortedList =
["inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
"inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
"inbound udp office 192.168.0.220 inside 10.1.0.13 53",
"inbound tcp office 192.168.0.125 inside 10.1.0.91 88"]
-or-
SortedList =
["inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
"inbound udp office 192.168.0.220 inside 10.1.0.13 53",
"inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
"inbound tcp office 192.168.0.125 inside 10.1.0.91 88"]
-or-
etc.

would be fine.

I'm reading a lot on sort, sorted, cmp, etc. but I'm just not getting
how to use an element of a string as a "key" within a list of strings.
I'm using Python 2.6.2.

Thanks

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


Re: How to sort a list of strings on a substring

2009-10-05 Thread Scott
On Oct 5, 6:05 pm, MRAB  wrote:
> Scott wrote:
> > I create a list of logs called LogList. Here is a sample:
>
> > LogList =
> > ["inbound tcp office 192.168.0.125 inside 10.1.0.91 88",
> > "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
> > "inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
> > "inbound udp office 192.168.0.220 inside 10.1.0.13 53"]
>
> > I want to sort the list on index 3 of each string - the first IP
> > Address.
>
> > I only need strings with similar, first IP's to be together. I don't
> > need all of the IP's to be in order. For example:
> > either:
> > SortedList =
> > ["inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
> > "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
> > "inbound udp office 192.168.0.220 inside 10.1.0.13 53",
> > "inbound tcp office 192.168.0.125 inside 10.1.0.91 88"]
> > -or-
> > SortedList =
> > ["inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
> > "inbound udp office 192.168.0.220 inside 10.1.0.13 53",
> > "inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
> > "inbound tcp office 192.168.0.125 inside 10.1.0.91 88"]
> > -or-
> > etc.
>
> > would be fine.
>
> > I'm reading a lot on sort, sorted, cmp, etc. but I'm just not getting
> > how to use an element of a string as a "key" within a list of strings.
> > I'm using Python 2.6.2.
>
> Forget about cmp, just use the 'key' argument of the list's 'sort'
> method or the 'sorted' function (the latter is better if you want to
> keep the original list). The 'key' argument expects a function (anything
> callable, actually) that accepts a single argument (the item) and
> returns a value to be used as the key, and the items will be sorted
> according to that key. In this case you want the items sorted by the
> fourth 'word', so split the item into words and return the one at index
> 3:
>
> def key_word(item):
>      return item.split()[3]
>
> SortedList = sorted(LogList, key=key_word)
>
> If the function is short and simple enough, lambda is often used instead
> of a named function:
>
> SortedList = sorted(LogList, key=lambda item: item.split()[3])

Ok, the lambda worked as advertised. THANK YOU!!

Thanks for giving both a def and lambda example. I'll be saving them.
-Scott
-- 
http://mail.python.org/mailman/listinfo/python-list


Sharing a program I wrote

2010-05-04 Thread Scott
I'm looking for suggestions on what to do (and how to do it) if I want
to share a program that I wrote in Python. There seem to be quite a
few places to post code and I don't know how to choose.

I wrote a program (script?) that takes a text file containing the
output of  the "show access-list" command on a Cisco PIX/ASA/FWSM
firewall and any number of text files containing syslog output from
the same firewall and creates a report showing which access-list rules
allowed which actual connections. It is written in Python 2.6 and runs
on Windows.

Since this is obviously something mankind has long been waiting for I
am thinking about sharing it - but since I am new to Python and
programming in general I am not at all familiar with dealing with
source code.

I'm sure that improvements and additions could be made if it was
reviewed by "actual programmers" but I wouldn't exactly call it a
"project" either. Of course I'd love to add a gui interface...

I've seen pypi. It seems to index code that is posted on all sorts of
sites - including pypi itself? And what is a "package" anyway? I've
seen sourceforge. It looks like a good home for big applications or
multi-developer projects. Freshmeat? Google code? My own website? Your
blog?

Another detail is that my program uses a library that was written by
someone else. It is the most excellent netaddr written by David P. D.
Moss and it lives at code.google.com. It uses the New BSD License.
Since this library is required would I simply provide a link to it?
Would I post the actual library? Do I have to post a copy of his
copyright info anywhere? Please don't tell me I have to write some
kind of installer that takes care of providing that.

I really just want anyone who might need a little networking/security
tool like this to be able to find it. Any advice?

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


Re: Sharing a program I wrote

2010-05-04 Thread Scott
James,

Thanks for the comprehensive reply. I would like to post it to
comp.lang.python but the main file is 169 lines long and the file for
functions is 316 lines long. I'm thinking that is a little long for
this format. Maybe I can put them up on a basic web page or file
sharing site and just post a link. Is that well received on this
forum?

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


Help running Windows programs from Python

2010-05-07 Thread Scott
I want to write a script to automate log archiving/compressing on a
Win2003 server. I have Python 2.6 installed. I am planning to use 7-
zip for compression (because I have been using it manually for a while
now). For now all operations will be local in the C: drive.

As a total beginner I'm having trouble grasping the control of
external programs.

I have found these options but have not tried any yet - I would like
some advice on which approach would be the most appropriate to begin
with.

Command Line Application Approach:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
All of the above recommend replacing with subprocess module
subprocess - latest way to do command line?
pexpect module - http://sourceforge.net/projects/pexpect/, Most recent
file is dated 1/5/2008
It should work on any platform that supports the standard Python
pty  module. (Windows?)
pty - "On Windows, only sockets are supported; on Unix, all
file descriptors." (gulp, ??)

COM Application Approach:
Per the 7-zip FAQ: Use the 7z.dll or 7za.dll - I haven't found these
files yet on sf.net.
comtypes 0.6.2 - has the word COM in it?
pywin32 / win32com  - there's that word again.

And then there is this whole idea of "wrappers."

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


Allocating memory to pass back via ctypes callback function

2009-06-18 Thread Scott
Hi,

I'm using python ctypes to interact with the C API of a commercial-off-
the-shelf application.  I need to implement callback functions which
will be called by the application.  The callbacks take as a parameter
a char** parameter for which the callback function will allocate
memory and set the value of the underlying char*.  The hitch is that I
need to allocate the memory with the vendor's own memory allocation
function because the caller will free the memory with the
corresponding vendor free function.  The problem is that I can't quite
work out how to set the address of the incoming POINTER(c_char_p)
parameter to the location provided by the memory allocation function.

def my_callback(pointer_c_char_p):

py_string = get_string_to_pass_back()

address = VENDOR_malloc( len(py_string)*sizeof(c_char) )

#  how to set pointer_c_char_p.contents to memory location
address?

#  would this be the correct next thing to do?
pointer_c_char_p.contents = c_char_p(py_string)
# 

return 0

Thanks,

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


Re: Allocating memory to pass back via ctypes callback function

2009-06-19 Thread Scott
I think I found the answer to my own question.  Can anyone spot any
issues with the following solution? The application I'm writing will
be hitting these callbacks pretty heavily so I'm nervous about mucking
up the memory management and creating one of those bugs that passes
undetected through testing but nails you in production.

def my_callback(p_cstring):
answer = 'foobar'

address = VENDOR_malloc(len(answer)+1)

cstring = c_char_p.from_address( address )

cstring.value = answer
p_cstring.contents = cstring
return
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Paul Scott

On 10/07/2013 14:22, Chris Angelico wrote:
Either that or it's funny only to other Australians. ChrisA 


As a South African, I found it funny too, but then again, we often get 
confused.


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


Re: Linux shell to python

2012-07-30 Thread Barry Scott
lspci gets all its information from the files in /sys/bus/pci/devices.

You can use os.listdir() to list all the files in the folder and then open
the files you want to get the data you need.

And of course you can write list comprehensions on as many lines as
it take to make the code maintainable.

Barry


On 30 Jul 2012, at 17:55, Paul van der Linden  wrote:

> You can do this with one subprocess.Popen and some python commands.
> The alternative is to pipe some subprocess.Popen commands together.
> Or for the quick way out (but I think you better stick with bash scripting 
> then): http://pypi.python.org/pypi/sarge/
> Don't know about it's stability/ubs/etc, never used it.
>  
> -Original message-
> From: Vikas Kumar Choudhary 
> Sent: Mon 30-07-2012 09:34
> Subject:  Linux shell to python
> To:   python-list@python.org; 
> Dear friends,
> 
> I just joined the group.
> I was trying porting from bash shell to python.
> 
>  
> let me know if someone has tried to implement (grep and PIPE)  shell commands 
> in python `lspci | grep Q | grep  "$isp_str1" | grep "$isp_str2" | cut -c1-7'
>  
> I tried to use python subprocess and OS.Popen modules.
> 
> Thanks & Regard's
> 
> Vikas Kumar Choudhary 
> 
> 
> (Yahoo,MSN-Hotmail,Skype) Messenger = vikas.choudhary
> Please Add Me in Your Messenger List for Better Communication
> P  Please consider the environment before printing this e-mail
> Do not print this email unless it is absolutely necessary. 
> Save papers, Save tree.
> 
> Note: This e-mail is confidential and may also be privileged, this is for the 
> intended recipients only. If you are not the intended recipient, please 
> delete the message and notify me immediately; you should not copy or use it 
> for any purpose, nor disclose its contents to any other person.
> 
> Notice:  All email and instant messages (including attachments) sent to or 
> from This E-mail id , may be retained, monitored and/or reviewed, or 
> authorized law enforcement personnel, without further notice or consent.
> --
>  
> -- 
>  http://mail.python.org/mailman/listinfo/python-list
>  
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Linux shell to python

2012-07-31 Thread Barry Scott


On 30 Jul 2012, at 23:56, Dan Stromberg  wrote:

> 
> On Mon, Jul 30, 2012 at 9:26 PM, Barry Scott  wrote:
> lspci gets all its information from the files in /sys/bus/pci/devices.
>  
> You can use os.listdir() to list all the files in the folder and then open
> the files you want to get the data you need.
> Gee, wouldn't it be more portable to parse lspci?  I wouldn't put it past the 
> (Linux) kernel devs to move the pseudo-filesystems around again...

No. The app is less stable the the linux user api gureentee.
I have been bitten with app output format changes but the /sys files have been
Reliable and far better focused at answering questions.

>  
> And of course you can write list comprehensions on as many lines as
> it take to make the code maintainable.
> Sigh, and I'm also not keen on multi-line list comprehensions, specifically 
> because I think they tend to make less readable code.  It also becomes a mess 
> when you need to insert print statements to get some visibility into what's 
> going on.
> 

With out trading examples of production code this is resolverable.

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


Re: Python does not take up available physical memory

2012-10-22 Thread Barry Scott
On 21 Oct 2012, at 15:14, Pradipto Banerjee 
 wrote:

> I tried this on a different PC with 12 GB RAM. As expected, this time, 
> reading the data was no issue. I noticed that for large files, Python takes 
> up 2.5x size in memory compared to size on disk, for the case when each line 
> in the file is retained as a string within a Python list. As an anecdote, for 
> MATLAB, the similar overhead is 2x, slightly lower than Python, and each line 
> in the file was retained as string within a MATLAB cell. I'm curious, has any 
> one compared the overhead of data in memory for other languages like for 
> instance Ruby?
> 
Python 3.3 has changes to make string storage more efficient. See the whats new 
page.
http://docs.python.org/py3k/whatsnew/3.3.html "more compact unicode strings".

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


Re: Missing something obvious with python-requests

2013-01-03 Thread Barry Scott
The shipped python library code does not work.

See http://bugs.python.org/issue7291 for patches.

Barry

On 3 Jan 2013, at 18:53, Ray Cote  wrote:

> Hello List:
> 
> I seem to be missing something obvious in terms of using proxies with the 
> requests module. 
> I'm using requests 1.4 and Python 2.7. Have tried this on Centos 6 and 
> Windows XP.
> 
> Here's the sample code, right out of the manual:
> 
> import requests
> 
> proxies = {
>'https': '192.168.24.25:8443',
>'http': '192.168.24.25:8443', }
> 
> a = requests.get('http://google.com/', proxies=proxies)
> 
> 
> When I look at the proxy log, I see a GET being performed -- when it should 
> be a CONNECT. 
> Does not matter if I try to get http or https google.com. 
> Clearly I'm missing something fundamental here. 
> But after two days of fiddling with the code and tracing through requests I'm 
> still unclear as to why requests is not using the proxy information.
> 
> Any help (or slap on the side of the head) appreciated. 
> Thanks
> --Ray
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple?

2013-01-03 Thread Barry Scott

On 2 Jan 2013, at 08:01, Victor Hooi  wrote:

> Hi,
> 
> I'm using pysvn to checkout a specific revision based on date - pysvn will 
> only accept a date in terms of seconds since the epoch.
> 
> I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to 
> seconds since epoch.
> 
> According to the docs, mktime expects a 9-element tuple.
> 
> My question is, how should I omit elements from this tuple? And what is the 
> expected behaviour when I do that?
> 
> For example, (zero-index), element 6 is the day of the week, and element 7 is 
> the day in the year, out of 366 - if I specify the earlier elements, then I 
> shouldn't really need to specify these.
> 
> However, the docs don't seem to talk much about this.
> 
> I just tried testing putting garbage numbers for element 6 and 7, whilst 
> specifying the earlier elements:
> 
>> time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 ))
> 
> It seems to have no effect what numbers I set 6 and 7 to - is that because 
> the earlier elements are set?

> 
> How should I properly omit them? Is this all documented somewhere? What is 
> the minimum I need to specify? And what happens to the fields I don't specify?

See the python docs the tuple is fully documented.
6 and 7 are not needed to figure out the seconds so are ignored.

Did you notice the parse_datetime.py that is in the pysvn Client Example? Its a 
rather
over the top date and time parser I wrote a long long time ago. (Which is 
missing some imports,
hmm I cannot have tested this for a long time). It can parse things like 
"yesterday 10:34".

Barry


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


Re: Forcing Python to detect DocumentRoot

2013-01-19 Thread Barry Scott

On 16 Jan 2013, at 13:51, Ferrous Cranus  wrote:

> When trying to open an html template within Python script i use a relative 
> path to say go one folder back and open index.html
> 
> f = open( '../' + page )
> 
> How to say the same thing in an absolute way by forcing Python to detect 
> DocumentRoot by itself?

In the general case it is not possible. There is no single convention you can 
use to detect the top of a web site.

If you always use apache httpd then read the value of DocumentRoot from 
httpd.conf

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


Re: python: HTTP connections through a proxy server requiring authentication

2013-01-28 Thread Barry Scott
The shipped python library code does not work.

See http://bugs.python.org/issue7291 for patches.

Barry

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


python25.dll

2012-03-04 Thread Scott V
 I don't know if anyone has sent this in before.
> I loaded the current version of Python on my computer to learn the
> programming and, I believe, it helps my Blender to work. Anyway,
> occassionally, I get an error on the screen, before I have started running
> programs, that states "python25.dll" will not load or does not exist.
> I have removed Python from my system to stop this error.
> Anything else I can do? This is XP system.
> Scott
*I loaded version 3.2, so not sure why the python25 was in there.

___
Amazon:
Check out my over 800 items for sale on Amazon at:

http://www.amazon.com/shops/bookman236  

"I believe that everything happens for a reason.
 People change so that you can learn to let go,
 things go wrong so that you appreciate them
 when they're right, you believe lies so you 
eventually learn to trust no one but yourself, 
and sometimes good things fall apart so better
 things can fall together." -Marilyn Monroe-- 
http://mail.python.org/mailman/listinfo/python-list


pygame.Rect question

2012-04-08 Thread Scott Siegler
Hello,

I am new to Python and began using pygame to start some game programming.  I 
was hoping someone could help me out with something that seems simple but is 
really confusing me.

I am creating a rect and then using the attributes of the rect to set the size 
and location.

I set rect.left to 30, rect.top to 30 and rect.width = 20

This works fine.  However, when looking at rect.right() it shows that it is 
equal to 50. I suppose this is equal to 30+20.  However, since the first pixel 
is on location 30, wouldn't the 20th pixel be on 49 (not 50)? 

Am I missing something here?  It is really confusing me when I am doing some 
collision algorithms.

Any help?

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


Re: How to call and execute C code in Python?

2012-05-16 Thread Barry Scott
There are many choices rather then raw python C API calls. Boost, PyCXX and 
ctypes are worth investigating. PyCXX requires you code in C++ but hides lots 
of the issues of using the Python API from you. It also supports python 2 and 
3. 

Barry - PyCXX maintainer

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


Help doing it the "python way"

2012-05-24 Thread Scott Siegler
Hello,

I am an experienced programmer but a beginner to python.  As such, I can figure 
out a way to code most algorithms using more "C" style syntax.

I am doing something now that I am sure is a more python way but i can't quite 
get it right.  I was hoping someone might help.

So I have a list of grid coordinates (x, y).  From that list, I want to create 
a new list that for each coordinate, I add the coordinate just above and just 
below (x,y+1) and (x,y-1)

right now I am using a for loop to go through all the coordinates and then 
separate append statements to add the top and bottom.

is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] 
or something along those lines?

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


Re: How to import Webkit and object in Official Python (not MacPorts python) without X11.

2012-05-26 Thread Barry Scott

On 26 May 2012, at 14:31, Mr.T Beppu wrote:

> I think that I will make a browser in Official Python (not MacPorts Python). 
> What should I do in order to install Webkit for Official Python (not MacPorts 
> Python) ? 
> from tokyo Japan.
> -- 
> http://mail.python.org/mailman/listinfo/python-list

The PyWebKit binding are not maintained and have problems. You will find
yourself getting very frustrated trying to get anything but the trivia working.

We ended up writing C++ code to use WebKit on Linux rather then our
preferred Python.

Barry

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


pygame: transparency question

2012-05-29 Thread Scott Siegler
Hello,

I have a surface that I load an image onto.  During a collision I would like to 
clear out the images of both surfaces that collided and show the score.  Is 
there a function call to clear a surface with an image?

One way I was thinking was to fill the surface with a color and then set that 
color as the colorkey.  Is this the only way or does pygame have a function to 
make the whole surface transparent?

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


Re: opening a file

2011-06-19 Thread Paul Scott
On Mon, 2011-06-20 at 08:14 +0200, Florencio Cano wrote:
> > This works:
> > infile=open('/foo/bar/prog/py_modules/this_is_a_test','r')
> >
> > This doesn't:
> > infile=open('~/prog/py_modules/this_is_a_test','r')
> >
> > Can't I work with files using Unix expressions?
> 
> You can use the glob module:
> http://docs.python.org/library/glob.html#module-glob

Regardless of the module that you use, you should also be using
os.path.join() to create paths. I never rely on hard coded paths
(especially since most of my code needs to run on multiple OS). In the
above example, you can easily put together a fairly complex path as
well, using os.path.join('foo', 'bar', 'prog', 'py_modules', ... ) which
will take care of what you need.

Not sure about regular python, but certainly in the wx GUI toolkit,
there is a wx.StandardPaths.Get() function which will get the user's
home or standard path where you can store all sorts of config data etc
in a hidden directory as well.

-- 
-- Paul

http://www.paulscott.za.net
http://twitter.com/paulscott56
http://www.chisimba.com


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


OSX application built with py2app can't see bundled PySide module?

2011-09-01 Thread Aaron Scott
I'm trying to deploy a Python app on OSX that was built with PySide. py2app 
packages it without issue, copying and linking a lot of PySide and Qt files in 
the process. But then, when I try to run the built app, I get this error:

Traceback (most recent call last):
  File 
"/Users/sequence/Desktop/code/dailies/dist/dailies_v02.app/Contents/Resources/__boot__.py",
 line 31, in 
_run('dailies_v02.py')
  File 
"/Users/sequence/Desktop/code/dailies/dist/dailies_v02.app/Contents/Resources/__boot__.py",
 line 28, in _run
execfile(path, globals(), globals())
  File 
"/Users/sequence/Desktop/code/dailies/dist/dailies_v02.app/Contents/Resources/dailies_v02.py",
 line 9, in 
from PySide.QtCore import *
  File "PySide/__init__.pyc", line 2, in 
  File "PySide/private.pyc", line 2, in 
  File "PySide/QtCore.pyc", line 18, in 
  File "PySide/QtCore.pyc", line 15, in __load
ImportError: '/usr/lib/python2.6/lib-dynload/PySide/QtCore.so' not found

The weird thing is, QtCore.so IS included in the application bundle: py2app 
copied it to the build under 
Contents/Resources/lib/python2.6/lib-dynload/PySide/. Is there a reason the 
application isn't seeing this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tail

2022-05-08 Thread Barry Scott



> On 7 May 2022, at 14:40, Stefan Ram  wrote:
> 
> Marco Sulla  writes:
>> So there's no way to reliably read lines in reverse in text mode using
>> seek and read, but the only option is readlines?
> 
>  I think, CPython is based on C. I don't know whether
>  Python's seek function directly calls C's fseek function,
>  but maybe the following parts of the C standard also are
>  relevant for Python?

There is the posix API that and the C FILE API.

I expect that the odities you about NUL chars is all about the FILE
API. As far as I know its the posix API that C Python uses and it
does not suffer from issues with binary files.

Barry

> 
> |Setting the file position indicator to end-of-file, as with
> |fseek(file, 0, SEEK_END), has undefined behavior for a binary
> |stream (because of possible trailing null characters) or for
> |any stream with state-dependent encoding that does not
> |assuredly end in the initial shift state.
> from a footnote in a draft of a C standard
> 
> |For a text stream, either offset shall be zero, or offset
> |shall be a value returned by an earlier successful call to
> |the ftell function on a stream associated with the same file
> |and whence shall be SEEK_SET.
> from a draft of a C standard
> 
> |A text stream is an ordered sequence of characters composed
> |into lines, each line consisting of zero or more characters
> |plus a terminating new-line character. Whether the last line
> |requires a terminating new-line character is implementation-defined.
> from a draft of a C standard
> 
>  This might mean that reading from a text stream that is not
>  ending in a new-line character might have undefined behavior
>  (depending on the C implementation). In practice, it might
>  mean that some things could go wrong near the end of such
>  a stream. 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: tail

2022-05-08 Thread Barry Scott



> On 7 May 2022, at 22:31, Chris Angelico  wrote:
> 
> On Sun, 8 May 2022 at 07:19, Stefan Ram  wrote:
>> 
>> MRAB  writes:
>>> On 2022-05-07 19:47, Stefan Ram wrote:
>> ...
 def encoding( name ):
   path = pathlib.Path( name )
   for encoding in( "utf_8", "latin_1", "cp1252" ):
   try:
   with path.open( encoding=encoding, errors="strict" )as file:
   text = file.read()
   return encoding
   except UnicodeDecodeError:
   pass
   return "ascii"
 Yes, it's potentially slow and might be wrong.
 The result "ascii" might mean it's a binary file.
>>> "latin-1" will decode any sequence of bytes, so it'll never try
>>> "cp1252", nor fall back to "ascii", and falling back to "ascii" is wrong
>>> anyway because the file could contain 0x80..0xFF, which aren't supported
>>> by that encoding.
>> 
>>  Thank you! It's working for my specific application where
>>  I'm reading from a collection of text files that should be
>>  encoded in either utf_8, latin_1, or ascii.
>> 
> 
> In that case, I'd exclude ASCII from the check, and just check UTF-8,
> and if that fails, decode as Latin-1. Any ASCII files will decode
> correctly as UTF-8, and any file will decode as Latin-1.
> 
> I've used this exact fallback system when decoding raw data from
> Unicode-naive servers - they accept and share bytes, so it's entirely
> possible to have a mix of encodings in a single stream. As long as you
> can define the span of a single "unit" (say, a line, or a chunk in
> some form), you can read as bytes and do the exact same "decode as
> UTF-8 if possible, otherwise decode as Latin-1" dance. Sure, it's not
> perfectly ideal, but it's about as good as you'll get with a lot of
> US-based servers. (Depending on context, you might use CP-1252 instead
> of Latin-1, but you might need errors="replace" there, since
> Windows-1252 has some undefined byte values.)

There is a very common error on Windows that files and especially web pages that
claim to be utf-8 are in fact CP-1252.

There is logic in the HTML standards to try utf-8 and if it fails fall back to 
CP-1252.

Its usually the left and "smart" quote chars that cause the issue as they code
as an invalid utf-8.

Barry
 

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

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


Re: tail

2022-05-08 Thread Barry Scott



> On 8 May 2022, at 17:05, Marco Sulla  wrote:
> 
> I think I've _almost_ found a simpler, general way:
> 
> import os
> 
> _lf = "\n"
> _cr = "\r"
> 
> def tail(filepath, n=10, newline=None, encoding=None, chunk_size=100):
>n_chunk_size = n * chunk_size

Why use tiny chunks? You can read 4KiB as fast as 100 bytes as its typically 
the smaller size the file system will allocate.
I tend to read on multiple of MiB as its near instant.

>pos = os.stat(filepath).st_size

You cannot mix POSIX API with text mode.
pos is in bytes from the start of the file.
Textmode will be in code points. bytes != code points.

>chunk_line_pos = -1
>lines_not_found = n
> 
>with open(filepath, newline=newline, encoding=encoding) as f:
>text = ""
> 
>hard_mode = False
> 
>if newline == None:
>newline = _lf
>elif newline == "":
>hard_mode = True
> 
>if hard_mode:
>while pos != 0:
>pos -= n_chunk_size
> 
>if pos < 0:
>pos = 0
> 
>f.seek(pos)

In text mode you can only seek to a value return from f.tell() otherwise the 
behaviour is undefined.

>text = f.read()

You have on limit on the amount of data read.

>lf_after = False
> 
>for i, char in enumerate(reversed(text)):

Simple use text.rindex('\n') or text.rfind('\n') for speed.

>if char == _lf:
>lf_after == True
>elif char == _cr:
>lines_not_found -= 1
> 
>newline_size = 2 if lf_after else 1
> 
>lf_after = False
>elif lf_after:
>lines_not_found -= 1
>newline_size = 1
>lf_after = False
> 
> 
>if lines_not_found == 0:
>chunk_line_pos = len(text) - 1 - i + newline_size
>break
> 
>if lines_not_found == 0:
>break
>else:
>while pos != 0:
>pos -= n_chunk_size
> 
>if pos < 0:
>pos = 0
> 
>f.seek(pos)
>text = f.read()
> 
>for i, char in enumerate(reversed(text)):
>if char == newline:
>lines_not_found -= 1
> 
>if lines_not_found == 0:
>chunk_line_pos = len(text) - 1 - i +
> len(newline)
>break
> 
>if lines_not_found == 0:
>break
> 
> 
>if chunk_line_pos == -1:
>chunk_line_pos = 0
> 
>return text[chunk_line_pos:]
> 
> 
> Shortly, the file is always opened in text mode. File is read at the end in
> bigger and bigger chunks, until the file is finished or all the lines are
> found.

It will fail if the contents is not ASCII.

> 
> Why? Because in encodings that have more than 1 byte per character, reading
> a chunk of n bytes, then reading the previous chunk, can eventually split
> the character between the chunks in two distinct bytes.

No it cannot. text mode only knows how to return code points. Now if you are in
binary it could be split, but you are not in binary mode so it cannot.

> I think one can read chunk by chunk and test the chunk junction problem. I
> suppose the code will be faster this way. Anyway, it seems that this trick
> is quite fast anyway and it's a lot simpler.

> The final result is read from the chunk, and not from the file, so there's
> no problems of misalignment of bytes and text. Furthermore, the builtin
> encoding parameter is used, so this should work with all the encodings
> (untested).
> 
> Furthermore, a newline parameter can be specified, as in open(). If it's
> equal to the empty string, the things are a little more complicated, anyway
> I suppose the code is clear. It's untested too. I only tested with an utf8
> linux file.
> 
> Do you think there are chances to get this function as a method of the file
> object in CPython? The method for a file object opened in bytes mode is
> simpler, since there's no encoding and newline is only \n in that case.

State your requirements. Then see if your implementation meets them.

Barry

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

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


Re: How to test characters of a string

2022-06-08 Thread Barry Scott


> On 7 Jun 2022, at 23:24, Dave  wrote:
> 
> Yes, it was probably just a typeo on my part.
> 
> I’ve now fixed the majority of cases but still got two strings that look 
> identical but fail to match, this time (again by 10cc), “I’m Mandy Fly Me”.
> 
> I’m putting money on it being a utf8 problem but I’m stuck on how to handle 
> it. It’s probably the single quote in I’m, although it has worked with other 
> songs.
> 
> Any ideas?

You can use difflib to give you a diff of the two strings:

:>>> print('\n'.join(difflib.unified_diff('abc', 'adc')))
---

+++

@@ -1,3 +1,3 @@

 a
-b
+d
 c
:>>>

The docs talk about lines, but difflib works on sequence. I use it a lot to find
differences within lines.

Barry



> 
> All the Best
> Cheers
> Dave
> 
> Here is the whole function/method or whatever it’s called in Python:
> 
> 
> #
> #   checkMusicFiles
> #
> 
> def checkMusicFiles(theBaseMusicLibraryFolder):
>myArtistDict = []
> 
> #
> #  Loop thru Artists Folder
> #
>myArtistsFoldlerList = getFolderList(theBaseMusicLibraryFolder)
>myArtistCount = 0
>for myArtistFolder in myArtistsFoldlerList:
>print('Artist: ' + myArtistFolder)
> #
> #  Loop thru Albums Folder
> #
>myAlbumList = getFolderList(theBaseMusicLibraryFolder + myArtistFolder)
>for myAlbum in myAlbumList:
>print('Album: ' + myAlbum)
> 
> #
> #  Loop thru Tracks (Files) Folder
> #
>myAlbumPath = theBaseMusicLibraryFolder + myArtistFolder + '/' + 
> myAlbum + '/'
>myFilesList = getFileList(myAlbumPath)
>for myFile in myFilesList:
>myFilePath = myAlbumPath + myFile
>myID3 = eyed3.load(myFilePath)
>if myID3 is None:
>continue
> 
>myArtistName = myID3.tag.artist
>if myArtistName is None:
>continue
> 
>myAlbumName = myID3.tag.album
>if myAlbumName is None:
>continue
> 
>myTitleName = myID3.tag.title
>if myTitleName is None:
>continue
> 
>myCompareFileName = myFile[0:-4]
>if myCompareFileName[0].isdigit() and 
> myCompareFileName[1].isdigit():
>myCompareFileName = myFile[3:-4]
> 
>if myCompareFileName != myTitleName:
>myLength1 = len(myCompareFileName)
>myLength2 = len(myTitleName)
>print('File Name Mismatch - Artist: [' + myArtistName + '] 
>  Album: ['+ myAlbumName + ']  Track: [' + myTitleName + ']  File: [' + 
> myCompareFileName + ']')
>if (myLength1 == myLength2):
>print('lengths match: ',myLength1)
>else:
>print('lengths mismatch: ',myLength1,'  ',myLength2)
> 
>print(' ')
> 
> 
> 
> 
>return myArtistsFoldlerList
> 
> 
> 
> 
> 
> 
>> On 8 Jun 2022, at 00:07, MRAB  wrote:
>> 
>> On 2022-06-07 21:23, Dave wrote:
>>> Thanks a lot for this! isDigit was the method I was looking for and 
>>> couldn’t find.
>>> I have another problem related to this, the following code uses the code 
>>> you just sent. I am getting a files ID3 tags using eyed3, this part seems 
>>> to work and I get expected values in this case myTitleName (Track name) is 
>>> set to “Deadlock Holiday” and myCompareFileName is set to “01 Deadlock 
>>> Holiday” (File Name with the Track number prepended). The is digit test 
>>> works and myCompareFileName is set to  “Deadlock Holiday”, so they should 
>>> match, right?
>> OT, but are you sure about that name? Isn't it "Dreadlock Holiday" (by 10cc)?
>> 
>> [snip]
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: How to replace characters in a string?

2022-06-08 Thread Barry Scott


> On 8 Jun 2022, at 18:01, Dave  wrote:
> 
> Hi,
> 
> This is a tool I’m using on my own files to save me time. Basically or most 
> of the tracks were imported with different version iTunes over the years. 
> There are two problems:
> 
> 1.   File System characters are replaced (you can’t have ‘/‘ or ‘:’ in a file 
> name).
ok
> 2.   Smart Quotes were added at some point, these need to replaced.
ok
> 3.   Other character based of name being of a non-english origin.
Why is this a problem? Its only if the chars are confusing/will not compare 
that there is something to fix?
All modern OS allow unicode filenames.

Barry


> 
> If find others I’ll add them.
> 
> I’m using MusicBrainz to do a fuzzy match and get the correct name.
> 
> it’s not perfect, but works for 99% of files which is good enough for me!
> 
> Cheers
> Dave
> 
> 
>> On 8 Jun 2022, at 18:23, Avi Gross via Python-list  
>> wrote:
>> 
>> Dave,
>> 
>> Your goal is to compare titles and there can be endless replacements needed 
>> if you allow the text to contain anything but ASCII.
>> 
>> Have you considered stripping out things instead? I mean remove lots of 
>> stuff that is not ASCII in the first place and perhaps also remove lots of 
>> extra punctuation likesingle quotes or question marks or redundant white 
>> space and compare the sort of skeletons of the two? 
>> 
>> And even if that fails, could you have a measure of how different they are 
>> and tolerate if they were say off by one letter albeit "My desert" matching 
>> "My Dessert" might not be a valid match with one being a song about an arid 
>> environment and the other about food you don't need!
>> 
>> Your seemingly simple need can expand into a fairly complex project. There 
>> may be many ideas on how to deal with it but not anything perfect enough to 
>> catch all cases as even a trained human may have to make decisions at times 
>> and not match what other humans do. We have examples like the TV show 
>> "NUMB3RS" that used a perfectly valid digit 3 to stand for an "E" but yet is 
>> often written when I look it up as NUMBERS. You have obvious cases where 
>> titles of songs may contain composite symbols like "œ" which will not 
>> compare to one where it is written out as "oe" so the idea of comparing is 
>> quite complex and the best you might do is heuristic.
>> 
>> UNICODE has many symbols that are almost the same or even look the same or 
>> maybe in one font versus another. There are libraries of functions that 
>> allow some kinds of comparisons or conversions that you could look into but 
>> the gain for you may not be worth it. Nothing stops a person from naming a 
>> song any way they want and I speak many languages and often see a song 
>> re-titled in the local language and using the local alphabet mixed often 
>> with another.
>> 
>> Your original question is perhaps now many questions, depending on what you 
>> choose. You started by wanting to know how to compare and it is moving on to 
>> how to delete parts or make substitutions or use regular expressions and it 
>> can get worse. You can, for example, take a string and identify the words 
>> within it and create a regular expression that inserts sequences between the 
>> words that match any zero or one or more non-word characters such as spaces, 
>> tabs, punctuation or non-ASCII, so that song titles with the same words in a 
>> sequence match no matter what is between them. The possibilities are endless 
>> but consider some of the techniques that are used by some programs that 
>> parse text and suggest alternate spellings  or even programs like Google 
>> Translate that can take a sentence and then suggest you may mean a slightly 
>> altered sentence with one word changed to fit better. 
>> 
>> You need to decide what you want to deal with and what will be 
>> mis-classified by your program. Some of us have suggested folding the case 
>> of the words but that means asong about a dark skinned person in Poland 
>> called "Black Polish" would match a song about keeping your shoes dark with 
>> "black polish" so I keep repeating it is very hard or frankly impossible, to 
>> catch every case I can imagine and the many I can't!
>> 
>> But the emphasis here is not your overall problem. It is about whether and 
>> how the computer language called python, and perhaps some add-on modules, 
>> can be used to solve each smaller need such as recognizing a pattern or 
>> replacing text. It can do quite a bit but only when the specification of the 
>> problem is exact. 
>> 
>> 
>> 
>> 
>> -Original Message-
>> From: Dave 
>> To: python-list@python.org
>> Sent: Wed, Jun 8, 2022 5:09 am
>> Subject: Re: How to replace characters in a string?
>> 
>> Hi,
>> 
>> Thanks for this! 
>> 
>> So, is there a copy function/method that returns a MutableString like in 
>> objective-C? I’ve solved this problems before in a number of languages like 
>> Objective-C and AppleScript.
>> 
>> Basically there is a set of common cha

Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Barry Scott



> On 22 Jun 2022, at 11:06, Lars Liedtke  wrote:
> 
> Could be unrelated and only a part of a solution, but if you are on a unixoid 
> system, you could use logrotate, instead of TimedRotatingFileHandler. 
> logfrotate ensures that the logging service does not realize, its logs have 
> been rotated. So it can log as if nothing has happened.


The process that is writing the file must be told that rotation has happened 
for it to work.
Other wise all the logs keep being write to the original file via the FD that 
the process has.

logrotate's config include how to tell the process the log file needs reopening.

Barry


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


Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Barry Scott


> On 22 Jun 2022, at 17:59, Paulo da Silva 
>  wrote:
> 
> Às 05:29 de 21/06/22, Paulo da Silva escreveu:
> 
> As a general response to some comments ...
> 
> Suppose we need to delete records from a database older than ...
> Today, it's usual to specify days. For example you have to keep some gov 
> papers for 90 days. This seems to come from computers era. In our minds, 
> however, we immediately think 90 days=3 months.
> For example, one may want to delete some files older than 9 months. It's far 
> more intuitive than 270 days.
> When we talk about years it is still going. For example I need to keep my 
> receipts for 5 years because IRS audits.
> Accepting this, it's intuitive, for example, that 3 months before July, 31 is 
> April, 30.
> The same happens for the years. 5 years before February, 29 is February, 28.

The advantage of 30 days, 90 days etc is that a contract or law does not need 
to tell you
how to deal with the problems of calendar months.

As you say in peoples thoughts that 1 month or 3 months etc. But an accounts 
department
will know how to to the number of days till they have to pay up.

Barry


> 
> Again, this is my opinion and that's the way I like it :-)
> Regards
> Paulo
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Building on Windows

2022-07-02 Thread Barry Scott



> On 2 Jul 2022, at 15:41, Sam Ezeh  wrote:
> 
> To add to this, my process was
> 
> 1. Setup the VM
> 2. Install Git
> 3. Clone CPython
> 4. Run `PCbuild\build.bat -d -e`
> 5. Notice the error, then install visual studio community 2022

Try running this:

call "C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

I use that to get at the command line tools.

If that does not work then search the disk for msbuild.exe and add its folder 
to your PATH.

Barry

> 6. Re-run `PCbuild\build.bat -d -e` and see the same error
> 
> I can't directly copy and paste between the VM and my host desktop but
> in this scenario, the error was that single line and I can use paste
> sites where necessary.
> 
> Kind regards,
> Sam Ezeh
> 
> On Sat, 2 Jul 2022 at 15:27, Sam Ezeh  wrote:
>> 
>> I have a Windows virtual machine and I'm following the instructions on
>> the devguide [1] to build Python inside it.
>> 
>> When running `PCbuild\build\bat -e -d` I get "Cannot locate
>> MSBuild.exe on PATH or as MSBUILD variable". I've done a minimal
>> amount of searching [2][3] but I'm not well-acquainted with Windows
>> and don't understand the solutions.
>> 
>> Thanks in advance.
>> 
>> Kind regards,
>> Sam Ezeh
>> 
>> [1]: https://devguide.python.org/compiler/
>> [2]: https://bugs.python.org/issue41213
>> [3]: https://bugs.python.org/issue33675
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Python 3.9 pidfd_open

2022-07-08 Thread Barry Scott



> On 5 Jul 2022, at 19:47, Weatherby,Gerard  wrote:
> 
> python introduced os.pidfd_open(), which works as documented.
> 
> My development environment, PyCharm, complains about it being undefined.
> 
> Should it be in 
> https://raw.githubusercontent.com/python/cpython/3.9/Lib/os.py ?

When faced with this type of problem I introspect from the Python REPL prompt.

Run python 3.9 and see if os.pidfd_open is defined?

Do not do this inside PyCharm to rule out a problem with PyCharm.

Also you will need to be running a linux kernel + glibc version that is new 
enough to proved this to python.

This is what I see with Fedora 36:

$ python3.9
Python 3.9.13 (main, Jun  9 2022, 00:00:00)
[GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
:>>> import os
:>>> os.pidfd_open

:>>>

Barry


> 
> --
> Gerard Weatherby | Application Architect
> NMRbox | NAN | Department of Molecular Biology and Biophysics | UConn Health
> 263 Farmington Avenue, Farmington, CT 06030-6406
> uchc.edu
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


script folder is empty

2022-07-17 Thread Scott Baer
I just installed Python 3.10.5 on a Windows 10 home ( Ver 21H2 OS build
1904431826).
I'm logged in with admin privileges
I did a custom install with  python-3.10.5-amd64.exe to C:\Program
Files\Python310
Installed with both For all Users & PIP selected.
;
once It was done installing, I rebooted and can run python:
Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

when I try to run:  pip --version
C:\Users\baerr>pip --version
'pip' is not recognized as an internal or external command,
operable program or batch file.

I've done some troubleshooting, and nothing is in the C:\Program
Files\Python310\Scripts folder.

I"m not a noob.. but obviously, I missing something..   I doubt this is a
bug.

Any help is much appreciated !!

Scott
bae...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple TCP proxy

2022-07-30 Thread Barry Scott
Morten,

As Chris remarked you need to learn a number of networking, python, system 
performance
and other skills to turn your project into production code.

Using threads does not scale very well. Its uses a lot of memory and raises CPU 
used
just to do the context switches. Also the GIL means that even if you are doing 
blocking
I/O the use of threads does not scale well.

Its rare to see multi threaded code, rather what you see is code that uses 
async I/O.

At its heart async code at the low level is using a kernel interface like epoll 
(or on old
systems select). What epoll allow you to do is wait on a sets of FDs for a 
range of
I/O operations. Like ready to read, ready to write and other activity (like the 
socket
closing).

You could write code to use epoll your self, but while fun to write you need to 
know
a lot about networking and linux to cover all the corner cases.

Libraries like twisted, trio, uvloop and pythons selectors implemented 
production quality
version of the required code with good APIs.

Do not judge these libraries by their size. They are no bloated and only as 
complex as
the problem they are solving requires.

There is a simple example of async code using the python selectors here that 
shows
the style of programming.
https://docs.python.org/3/library/selectors.html#examples 


The issues that you likely need to solve and test for include:
* handling unexpected socket close events.
* buffering and flow control from one socket's read to the another socket's 
write.
  What if one side is reading slower then the other is writing?
* timeout sockets that stop sending data and close them

At some point you will exceed the capacity for one process to handle the load.
The solution we used is to listen on the socket in a parent process and fork
enough child processes to handle the I/O load. This avoids issues with the GIL
and allows you to scale.

But I am still not sure why you need to do anything more the increase the 
backlog
on your listen socket in the main app. Set the backlog to 1,000,000 does that 
fix
your issue? 

You will need on Linux to change kernel limits to allow that size. See man 
listen
for info on what you need to change.

Barry

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


Re: why I cannot to install packages?

2022-09-15 Thread Barry Scott


> On 15 Sep 2022, at 12:31, ⁨נתי שטרן⁩ <⁨nsh...@gmail.com⁩> wrote:
> 
> [image: image.png]

Images are stripped; please copy the text of the error you are seeing and post 
that.

Barry

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

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


Re: Python 3.9.14

2022-09-15 Thread Barry Scott


> On 14 Sep 2022, at 14:03, ⁨אורי⁩ <⁨u...@speedy.net⁩> wrote:
> 
> Hi,
> 
> Python 3.9.14 has been released on Sept. 6, 2022. As I can see written on
> https://www.python.org/downloads/release/python-3914/:
> 
> According to the release calendar specified in PEP 596, Python 3.9 is now
> in the "security fixes only" stage of its life cycle: the 3.9 branch only
> accepts security fixes and releases of those are made irregularly in
> source-only form until October 2025. Python 3.9 isn't receiving regular bug
> fixes anymore, and binary installers are no longer provided for it. Python
> 3.9.13 was the last full bugfix release of Python 3.9 with binary
> installers.
> 
> 
> Is there a safe way to install a 64-bit version of Python 3.9.14 on Windows?

What is stopping you using 3.10?

If 3.9 is important then I guess you will need to build it for yourself.

Barry

> 
> Thanks,
> Uri.
> אורי
> u...@speedy.net
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Changing 'Scripts/*.exe'

2022-10-03 Thread Barry Scott



> On 1 Oct 2022, at 16:50, Gisle Vanem via Python-list  
> wrote:
> 
> Hello list.
> 
> I'm moved my old Python27 installation from
>  f:\ProgramFiler\Python27  ( == 'ProgramFiles')
> to
>  f:\gv\Python27

The design of Windows installed software makes this hard to do without a lot of 
knowledge about what the installation did.

For example there are registry keys that hold information on where python 2.7 
is installed and there is other software that
will read the registry and expect that information to be correct.

I would have backed the old installation, uninstalled and the reinstalled 
python where you want it to be.

> 
> and now many 'scripts/*.exe' program fails
> to start since the old path to 'Python.exe'
> is wrong.
> 
> E.g. 'Scripts/pip2.exe' has the path
> "f:\programfiler\python27\python.exe" hard-coded
> inside it.
> 
> Is there a easy way to fix this w/o re-installing this
> old Python?

The advice you have had will get you someway to fixing the breakage.
But do not be surprised if more things break as you try different things out.

As I say I would have backed up the files, uninstall and reinstall then put 
back from backup
any files that are not installable anymore.

Why did you move the files from where they where installed and working?

Barry


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

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


Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-24 Thread Barry Scott


> On 8 Oct 2022, at 11:50, Weatherby,Gerard  wrote:
> 
> Logging does support passing a callable, if indirectly. It only calls __str__ 
> on the object passed if debugging is enabled.
>  
> class Defer:
> 
> def __init__(self,fn):
> self.fn = fn
> 
> def __str__(self):
> return self.fn()
> 
> def some_expensive_function():
> return "hello"
> 
> logging.basicConfig()
> logging.debug(Defer(some_expensive_function))

Oh what a clever hack. Took a few minutes of code reading to see why this works.
You are exploiting the str(msg) that is in class LogRecords getMessage().

```
def getMessage(self):
"""
Return the message for this LogRecord.

Return the message for this LogRecord after merging any user-supplied
arguments with the message.
"""
msg = str(self.msg)
if self.args:
msg = msg % self.args
return msg
```

Barry


>  
>  
> From: Python-list  > on behalf of 
> Barry mailto:ba...@barrys-emacs.org>>
> Date: Friday, October 7, 2022 at 1:30 PM
> To: MRAB mailto:pyt...@mrabarnett.plus.com>>
> Cc: python-list@python.org  
> mailto:python-list@python.org>>
> Subject: Re: Ref-strings in logging messages (was: Performance issue with 
> CPython 3.10 + Cython)
> 
> *** Attention: This is an external email. Use caution responding, opening 
> attachments or clicking on links. ***
> 
> > On 7 Oct 2022, at 18:16, MRAB  wrote:
> >
> > On 2022-10-07 16:45, Skip Montanaro wrote:
> >>> On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames 
> >>> 
> >>> wrote:
> >>> 1. The culprit was me. As lazy as I am, I have used f-strings all over the
> >>> place in calls to `logging.logger.debug()` and friends, evaluating all
> >>> arguments regardless of whether the logger was enabled or not.
> >>>
> >> I thought there was some discussion about whether and how to efficiently
> >> admit f-strings to the logging package. I'm guessing that's not gone
> >> anywhere (yet).
> > Letting you pass in a callable to call might help because that you could 
> > use lambda.
> 
> Yep, that’s the obvious way to avoid expensive log data generation.
> Would need logging module to support that use case.
> 
> Barry
> 
> > --
> > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!mrESxAj9YCHsdtNAfkNiY-Zf6U3WTIqaNrgBmbw1ELlQy51ilob43dD0ONsqvg4a94MEdOdwomgyqfyABbvRnA$
> >  
> > 
> >
> 
> --
> https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!mrESxAj9YCHsdtNAfkNiY-Zf6U3WTIqaNrgBmbw1ELlQy51ilob43dD0ONsqvg4a94MEdOdwomgyqfyABbvRnA$
>  
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Any PyQt developers here?

2022-10-25 Thread Barry Scott
There is an active PyQt mailing list that has lots of helpful and knowledgeable 
people on it.

https://www.riverbankcomputing.com/mailman/listinfo/pyqt

Barry


> On 25 Oct 2022, at 18:03, DFS  wrote:
> 
> Having problems with removeRow() on a QTableView object.
> 
> After calling removeRow(), the screen isn't updating.  It's as if the model 
> is read-only, but it's a QSqlTableModel() model, which is not read-only.
> 
> The underlying SQL is straightforward (one table) and all columns are 
> editable.
> 
> None of the editStrategies are working either.
> 
> I tried everything I can think of, including changes to the EditTriggers, but 
> no luck.  HELP!
> 
> FWIW, the same removeRow() code works fine with a QTableWidget.
> 
> ---
> object creation and data loading all works fine
> ---
> #open db connection
> qdb = QSqlDatabase.addDatabase("QSQLITE")
> qdb.setDatabaseName(dbname)
> qdb.open()
> 
> #prepare query and execute to return data
> query = QSqlQuery()
> query.prepare(cSQL)
> query.exec_()
> 
> #set model type and query
> model = QSqlTableModel()
> model.setQuery(query)
>   
> #assign model to QTableView object
> view = frm.tblPostsView
> view.setModel(model)
>   
> #get all data
> while(model.canFetchMore()): model.fetchMore()
> datarows = model.rowCount()
> 
> 
> 
> ---
> iterate selected rows also works fine
> SelectionMode is Extended.
> identical code works for a QTableWidget
> ---
> selected = tbl.selectionModel().selectedRows()
> #reverse sort the selected items to delete from bottom up
> selected = sorted(selected,reverse=True)
> for i,val in enumerate(selected):
>   tbl.model().removeRow(selected[i].row())
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: UTF-8 and latin1

2022-10-25 Thread Barry Scott


> On 25 Oct 2022, at 11:16, Stefan Ram  wrote:
> 
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> You can let Python guess the encoding of a file.
>> def encoding_of( name ):
>> path = pathlib.Path( name )
>> for encoding in( "utf_8", "cp1252", "latin_1" ):
>> try:
>> with path.open( encoding=encoding, errors="strict" )as file:
> 
>  I also read a book which claimed that the tkinter.Text
>  widget would accept bytes and guess whether these are
>  encoded in UTF-8 or "ISO 8859-1" and decode them 
>  accordingly. However, today I found that here it does 
>  accept bytes but it always guesses "ISO 8859-1".

The best you can do is assume that if the text cannot decode as utf-8 it may be 
8859-1.

Barry

> 
>  main.py
> 
> import tkinter
> 
> text = tkinter.Text()
> text.insert( tkinter.END, "AÄäÖöÜüß".encode( encoding='ISO 8859-1' ))
> text.insert( tkinter.END, "AÄäÖöÜüß".encode( encoding='UTF-8' ))
> text.pack()
> print( text.get( "1.0", "end" ))
> 
>  output
> 
> AÄäÖöÜüßAÄäÖöÜüß
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Information about slow execution notebook

2022-11-01 Thread Barry Scott



> On 1 Nov 2022, at 16:08, nhlanhlah198506  wrote:
> 
> I wish to know why sometimes my notebook won't execute my program And VS code 
> won't connect to kernels. Thank you Nhlanhla Ndwandwe Sent from my Galaxy

You need to provide details on what you do and what happens.
Reminder do not attach screen shots, they are striped in this mailing list.
Cut-n-paste full error message information.

Barry


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

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


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Barry Scott


> On 7 Nov 2022, at 09:28, Chris Green  wrote:
> 
> Chris Green  wrote:
>>> 3: with your pseudo "python3" script in place, make all the scripts use 
>>> the "#!/usr/bin/env python3" shebang suggested above.
>>> 
>> Yes, that sounds a good plan to me, thanks Cameron.
>> 
> Doesn't '#!/usr/bin/env python3' suffer from the same problem as
> '#!/usr/bin/python3' in the sense that the env executable might not be
> in /usr/bin?

env is always available as /usr/bin/env - I think its spec'ed in posix that way.

The only reason that things are in /bin are for systems that need a subset of
programs to boot the system to point it can mount /usr. env is not going to be
needed for that use case.

> 
> Wouldn't '#! env python3' be better?

Barry

> 
> -- 
> Chris Green
> ·
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Python 3.11.0 installation and Tkinter does not work

2022-11-23 Thread Barry Scott


> On 23 Nov 2022, at 06:31, Stefan Ram  wrote:
> 
> darkst...@o2online.de writes:
>> I want learn python for 4 weeks and have problems, installing Tkinter. If I=
>> installed 3.11.0 for my windows 8.1 from python.org and type
> 
>  Ok, so you already installed from python.org. I wonder a
>  little about the wording "installing Tkinter". Here,
>  I installed /Python/ from python.org, and this /included/ tkinter.
>  If you have really attempted a separate installation of tkinter,
>  it may help to uninstall and instead install Python /including/ 
>  tkinter.
> 
>>> ImportError: DLL load failed while importing _tkinter: Das angegebene
>>> Modul wurde nicht gefunden.
> 
>  Another possibility of analysis is to watch the Python
>  process using "Process Monitor" (formerly from Sysinternals)
>  under Microsoft® Windows (not to be confused with "Process
>  Explorer"). This program requires some familiarization,
>  but then it can show you in which directories a process is
>  searching for which DLLs. This might help you to find the
>  name of the DLL missing and in which directory it should be.

I think the depends.exe tool from sysintenals will do this as well.
There is a mode where you run a program and it collects the data
for all the DLLs that are used either statically linked or dynamicall
loaded, that is the case for _tkinter.

I have not used in in a very long time but I recall it shows errors
from DLLs that failed to load.

Barry


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

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


Re: NEO6 GPS with Py PICO with micropython

2022-11-30 Thread Barry Scott



> On 30 Nov 2022, at 10:58, KK CHN  wrote:
> 
> List,
> 
> Just commented the // gpsModule.readline() in the while loop,  (
> refer the link
> https://microcontrollerslab.com/neo-6m-gps-module-raspberry-pi-pico-micropython/
> )
> 
> 
> while True: # gpsModule.readline() // This line commented out and the "GPS
> not found message disappeared". buff = str(gpsModule.readline()) parts =
> buff.split(',')
> 
> 
> The GPS not found error which appears intermittently in the output python
> console for few seconds ( say 7 to 8 seconds  its printing the lines   "
> GPS data not found" )   now  disappears.
> 
> Any thoughts?  How the above line comment made it vanish the  "GPS data
> not found" error output.

Show the full text of the error that you see. Is it a traceback?

What I would do then is read the code that raised the "GPS data not found"
error and find out why it reports that error.

Barry
p.s. Please reply in line, do not top post.

> 
> Krishane
> 
> On Wed, Nov 30, 2022 at 3:58 AM rbowman  wrote:
> 
>> On Tue, 29 Nov 2022 17:23:31 +0530, KK CHN wrote:
>> 
>> 
>>> When I ran the program I am able to see the output of  latitude and
>>> longitude in the console of thony IDE.  But  between certain intervals
>>> of a few seconds  I am getting the latitude and longitude data ( its
>>> printing GPS data not found ?? ) in the python console.
>> 
>> I would guess the 8 seconds in
>> 
>> timeout = time.time() + 8
>> 
>> is too short. Most GPS receivers repeat a sequence on NMEA sentences and
>> the code is specifically looking for $GPGGA. Add
>> 
>> print(buff)
>> 
>> to see the sentences being received. I use the $GPRMC since I'm interested
>> in the position, speed, and heading. It's a different format but if you
>> only want lat/lon you could decode it in a similar fashion as the $GPGGA.
>> 
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Does one have to use curses to read single characters from keyboard?

2022-12-11 Thread Barry Scott


> On 11 Dec 2022, at 18:50, Chris Green  wrote:
> 
> My solution in the end was copied from one I found that was much
> simpler and straightforward than most.  I meant to post this earlier
> but it got lost somewhere:-
> 
>import sys, termios, tty
>#
>#
># Read a single character from teminal, specifically for 'Y/N' 
>#
>fdInput = sys.stdin.fileno()
>termAttr = termios.tcgetattr(0)
>#
>#
># Get a single character, setcbreak rather than setraw meands CTRL/C
>etc. still work
>#
>def getch():
>sys.stdout.flush()
>tty.setcbreak(fdInput)
>ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding)

Will not work for uncode code points above 255.

This is what happened when I typed € key:

:>>> a.getch()
Traceback (most recent call last):
  File "", line 1, in 
  File "/private/var/folders/ll/08dwwqkx6v9bcd15sh06x14wgn/T/a.py", line 
15, in getch
ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 0: 
unexpected end of data

You would need to have a loop that collected all the utf-8 bytes of a single 
code point.
You can to look at the first byte of know if the utf-8 is 1, 2, 3 or 4 bytes 
for a code point.

Barry

>termios.tcsetattr(fdInput, termios.TCSAFLUSH, termAttr)
>sys.stdout.write(ch)
>return ch
>#
>#
># Get a y or n answer, ignore other characters
>#
>def getyn():
>ch = 'x'
>while ch != 'y' and ch != 'n':
>ch = getch().lower()
>return ch
> 
> So getyn() reads a y or an n, ignores anything else and doesn't wait
> for a return key.  Keyboard input operation is restored to normal
> after doing this. Using tty.setcbreak() rather than tty.setraw() means
> that CTRL/C etc. still work if things go really wrong.

> 
> 
> -- 
> Chris Green
> ·
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Possible re bug

2022-12-29 Thread Barry Scott

Please please fix you email client so that your replies stay with the
emails you are replying to.

Barry


On 28/12/2022 19:09, Stefan Ram wrote:

Alexander Richert writes:
|print(re.findall(".*","pattern"))
|yields ['pattern',''] which is not what I was expecting.

   The asterisk is "greedy", so I agree that it should consume
   /everything/ including all the empty strings at the end.
   To work around this, one can use '^.*' (no smiley intended).



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


Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Barry Scott



On 04/01/2023 02:26, Chris Angelico wrote:

Reading/writing the FD is the same as using stdout (technically you'd
write to fd 1 and read from fd 0), but yes, can use /dev/tty to reach
for the console directly.


I think the logic is more like checking that stdin is a tty then using
the tty it to read and write the tty. This works with stdout redirected.
Also stdin is likely only open with read access.

For example the way to prevent ssh-add from prompting in the terminal is 
this:


$ ssh-add ~/.ssh/id_rsa https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   9   10   >