Determine attributes of calling method

2011-06-03 Thread Joe
Hello,

I'm trying to implement a way to restrict method usage based on the
caller's attributes.  In the following example I'd like to execute the
server method "bar" only if the caller's method has a "blue" value for
it's color attribute.

The current output is:

blue
red
bar
bar

I'd like it to be:

blue
red
bar

I've worked my way through inspect but that doesn't seem to be the
right approach.

# Example
class Client:

def __init__(self, server):
self.server=server

def foo(self):
self.server.bar()

def fu(self):
self.server.bar()

foo.__dict__['color']='blue'
fu.__dict__['color']='red'

class BlueServer:

def bar(self):
"""
Goal is to only accept calls from "blue" client methods.
Don't know how to do it :(
    """
print "bar"

s=BlueServer()
c=Client(s)
print c.foo.color
print c.fu.color
c.foo()
c.fu()

Thanks for your help!

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


adodbapi integer parameters and MS Access

2011-03-13 Thread Joe
Here is my environment:

Windows 7 x64 SP1
Python 3.2
adodbapi 2.4.2
MS Access

Although the above environment is what I am currently using I have
encountered this same problem with Python 3.1.1.   It is not a problem
with Python 2.x.

The problem is as follows:

If you are using a select statement like:

select col_1, col_2 from table where (col_1 = ?)

and you are using the qmark parameter style

and you pass in an integer (for example:  (1, )) for the parameters,
you get the following error:

(-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider
for ODBC Dri
vers', '[Microsoft][ODBC Microsoft Access Driver]Optional feature not
implemente
d ', None, 0, -2147217887), None)
Command:

select col_1, col_2 from table where (col_1 = ?)

Parameters:
[Name: p0, Dir.: Input, Type: adBigInt, Size: 0, Value: "1",
Precision: 0, Numer
icScale: 0]


If you run the same code using pyodbc or odbc in Python 3.2 (or 3.1.1)
it works fine so I know it is not a problem with the ODBC driver.

If you run the same code in Python 2.6.2 and adodbapi it also runs
fine.

Further investigation using different tables and columns seems to
conclude that:

adodbapi + Python 3.x + qmark parameters + parameters that are
integers produces this error.

col_1 in the database is defined as a number (long integer with 0
decimal positions).

If you convert the parameter to a string (str(1), ) then adodbapi
works in Python 3.2.

Is this a known bug?
-- 
http://mail.python.org/mailman/listinfo/python-list


Multimeter USB output

2016-08-27 Thread Joe

Hi,

I'm using Python 3.5.1 with PyUSB 1.0 under Win 10 (64). We try to read 
the USB output of a DMM 'UT61B'.


import usb.core
import usb.util
import usb.backend.libusb1

def Gosub():
 dev = usb.core.find(idVendor=0x1a86, idProduct=0xe008) # Digital 
Multimeter UT61B

 if dev == None:
 print ('Multimeter not found')
 else:
 print ('Multimeter was found')
 dev.set_configuration()
 cfg = dev.get_active_configuration()
 intf = cfg[(0,0)]
 ep = usb.util.find_descriptor(
 intf,
 custom_match = \
 lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
 if ep == None:
 print ('ep is None')
 else:
 s = ep.read(64, 500)
 print ('Len s: ' + len(s))

print ('Starting')
Gosub()
print ('Ready.-')

Result:

File "d:\work-d\PythonProgs\ut61b.py", line 27, in 
   Gosub()
File "d:\work-d\PythonProgs\ut61b.py", line 23, in Gosub
   s = ep.read(64, 500)
File "D:\Python3\Lib\site-packages\usb\core.py", line 402, in read
   return self.device.read(self, size_or_buffer, timeout)
File "D:\Python3\Lib\site-packages\usb\core.py", line 988, in read
   self.__get_timeout(timeout))
File "D:\Python3\Lib\site-packages\usb\backend\libusb1.py", line 851, in 
intr_read

   timeout)
File "D:\Python3\Lib\site-packages\usb\backend\libusb1.py", line 936, in 
__read

   _check(retval)
File "D:\Python3\Lib\site-packages\usb\backend\libusb1.py", line 595, in 
_check

   raise USBError(_strerror(ret), ret, _libusb_errno[ret])

usb.core.USBError: [Errno 10060] Operation timed out

What's wrong? How to fix?

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


Multimeter USB output

2016-08-28 Thread Joe


Am 28.08.2016 um 00:45 schrieb Terry Reedy:
> On 8/27/2016 3:35 PM, Joe wrote:
>> Hi,
>>
>> I'm using Python 3.5.1 with PyUSB 1.0 under Win 10 (64). We try to read
>> the USB output of a DMM 'UT61B'.
>>
>> import usb.core
>> import usb.util
>> import usb.backend.libusb1
>>
>> def Gosub():
>>  dev = usb.core.find(idVendor=0x1a86, idProduct=0xe008) # Digital
>> Multimeter UT61B
>>  if dev == None:
>>  print ('Multimeter not found')
>>  else:
>>  print ('Multimeter was found')
>>  dev.set_configuration()
>>  cfg = dev.get_active_configuration()
>>  intf = cfg[(0,0)]
>>  ep = usb.util.find_descriptor(
>>  intf,
>>  custom_match = \
>>  lambda e: \
>> usb.util.endpoint_direction(e.bEndpointAddress) == \
>> usb.util.ENDPOINT_IN)
>>  if ep == None:
>>  print ('ep is None')
>>  else:
>>  s = ep.read(64, 500)
>>  print ('Len s: ' + len(s))
>>
>> print ('Starting')
>> Gosub()
>> print ('Ready.-')
>>
>> Result:
>
> I presume you saw
> Starting
> Multimeter was found
>
>> File "d:\work-d\PythonProgs\ut61b.py", line 27, in 
>>Gosub()
>> File "d:\work-d\PythonProgs\ut61b.py", line 23, in Gosub
>>s = ep.read(64, 500)
>> File "D:\Python3\Lib\site-packages\usb\core.py", line 402, in read
>>return self.device.read(self, size_or_buffer, timeout)
>> File "D:\Python3\Lib\site-packages\usb\core.py", line 988, in read
>>self.__get_timeout(timeout))
>> File "D:\Python3\Lib\site-packages\usb\backend\libusb1.py", line 851, in
>> intr_read
>>timeout)
>> File "D:\Python3\Lib\site-packages\usb\backend\libusb1.py", line 936, in
>> __read
>>_check(retval)
>> File "D:\Python3\Lib\site-packages\usb\backend\libusb1.py", line 595, in
>> _check
>>raise USBError(_strerror(ret), ret, _libusb_errno[ret])
>>
>> usb.core.USBError: [Errno 10060] Operation timed out
>>
>> What's wrong? How to fix?
>
> Read (again?) the doc for the interface for the device.  Because reading
> timed out, I suspect that it is waiting for a command for it to send
> something.
>

Yes, I saw this:

Starting
Multimeter was found

The UT61B has two interfaces, a RS232C interface and this usb interface. 
The RS232 interface works well with PySerial. It continously transmits 2 
.. 3 Pakets per second with 14 Bytes each. This happens unsolicited 
without any command as long as the RS232C/USB button on the DMM is active.


So I assumed the USB interface also doesn't need any command and also
transmit this stream of 2 to 3 Pakets per second. But unfortunately I 
don't have any doc for the USB interface for this device.


To the accompanying software of the UT61B there is a ready windos app 
which shows and logs the output of the UT61B. This app can be switched 
between RS232C and USB; both work.


I asked the manufacturer (Uni-T in Shenzen) for additional info and are 
now waiting for an answer.


Assumed the USB interface sends this 2 to 3 pakets per second 
unsolicited - should the code shown work? Is this ok:



>>  lambda e: \
>> usb.util.endpoint_direction(e.bEndpointAddress) == \
>> usb.util.ENDPOINT_IN)

I am in doubt: Is usb.util.ENDPOINT_IN really correct?

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


Re: Is duck-typing misnamed?

2016-08-28 Thread Joe

Am 28.08.2016 um 00:34 schrieb Terry Reedy:

On 8/26/2016 7:58 PM, ROGER GRAYDON CHRISTMAN wrote:

"If it walks like a duck, quacks like a duck,... "

so there is indeed precedence for this so-called 'duck typing'


but wouldn't it be more Pythonic to call this 'witch typing'?

"How do you know she is a witch?"

"She looks like one."


Given that people were once burned to death for 'looking like a witch'
(or sounding or acting), and can still suffer socially for such reasons,
this it not funny to me.  We should stick with ducks.


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


Re: Multimeter USB output

2016-08-29 Thread Joe

Am 28.08.2016 um 17:22 schrieb Dennis Lee Bieber:

If you can read spaghetti coded C, you might want to study
https://sourceforge.net/projects/ut61/


Interesting, but... The last time I did something with c, it was with 
BDS-C under CM/M. Somebody remenbering this no-fp compiler from the dark 
age before PC und Linux?

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


Re: Multimeter USB output

2016-08-29 Thread Joe

Am 29.08.2016 um 10:54 schrieb Joe:

it was with BDS-C under CM/M.


under CP/M, of course.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Multimeter USB output

2016-08-30 Thread Joe

Am 30.08.2016 um 06:24 schrieb Paul Rubin:

Larry Hudson  writes:

with BDS-C under CP/M. Somebody remenbering this no-fp compiler from
the dark age before PC und Linux?

I remember it well.  It's what I used to initially learn C.


Source code is online here:

http://www.bdsoft.com/resources/bdsc.html

I've looked at it a little.  I don't know if I ever might have had it in
me to write big chunks of asm code like that.  Wow!


Great surprise. Very interesting this link. Thank you, Paul.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Multimeter USB output

2016-08-30 Thread Joe

Am 30.08.2016 um 13:01 schrieb D'Arcy J.M. Cain:

On Mon, 29 Aug 2016 21:21:05 -0700
Larry Hudson via Python-list  wrote:

I remember it well.  It's what I used to initially learn C.  I'm a
completely self-taught, hobby programmer.  Been around since the MITS
Altair.  How many remember that beast??


Remember it and still have it in the basement.

I read a lot about the Altair in Byte in those days, but never had a 
chance to touch it. Wasn't it horrible expensive?

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


Re: [OT] Altair

2016-08-30 Thread Joe

Am 30.08.2016 um 17:52 schrieb D'Arcy J.M. Cain:

On Tue, 30 Aug 2016 15:56:07 +0200
Joe  wrote:

Am 30.08.2016 um 13:01 schrieb D'Arcy J.M. Cain:

On Mon, 29 Aug 2016 21:21:05 -0700
Larry Hudson via Python-list  wrote:

I remember it well.  It's what I used to initially learn C.  I'm a
completely self-taught, hobby programmer.  Been around since the
MITS Altair.  How many remember that beast??


Remember it and still have it in the basement.


I read a lot about the Altair in Byte in those days, but never had a
chance to touch it. Wasn't it horrible expensive?


I can't remember what is was going for but I bought mine used for
$1,000.  It had a number of add-ons including a keyboard and floppy
drives.  The power supply was also beefed up.

It also had a replacement bezel.  It seems that the original Altair's
silk screened front panel was crappy and rubbed off easily.  Some
company sold one but it says "Cycloid" instead of "Altair" on it.



I think the first BASIC Interpreter ever sold by Gates & Friend was for 
this machine? How did you use your floppy drives on this machine 
(Open-Write-Close)?


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


Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Joe
How to find the number of robots needed to walk through the rectangular grid
The movement of a robot in the field is divided into successive steps

In one step a robot can move either horizontally or vertically (in one row or 
in one column of cells) by some number of cells

A robot can move in one step from cell X to cell Y if and only if the distance 
between the centers of the cells X and Y is equal to the sum of integers 
contained in X and Y

Cell X is reachable for robot A if either A is currently standing in the cell X 
or A can reach X after some number of steps. During the transfer the robot can 
choose the direction (horizontal or vertical) of each step arbitrarily
[![enter image description here][1]][1]

I started implementing it by first checking the row and print the index of the 
Cell X and Y where the distance is equal to the sum of integers contained in X 
and Y 

but after coding I found it difficult to remember the index when moving 
vertically

 So I thought to Build a graph where nodes are grid cells and edges are legal 
direct movements, then run any connected components algorithm to find which 
cells are reachable from each other


Can anyone implement it with graphs or queue?





Input 

4 6
3 1 3 2 0 0
1 3 2 1 2 1
3 3 1 0 1 2
1 2 0 2 3 3

Output 

6

My code so far

def row_walk(inputstring):
inputs = inputstring.split(" ")
row_number, column_number = int(inputs[0]), int(inputs[1])  
matrix = [list(map(int, input().split())) for _ in range(row_number)]
matrix_transposed = (np.transpose(matrix)).tolist() 

used = set()
for i, r1 in enumerate(matrix[0]):
for j, r2 in enumerate(matrix[0]):
if j > i and  r1+r2 == j-i:
used.update((i, j))

cell_movement = [x for x in range(len(matrix[0])) if x not in used]
trivial_cell = [y for y in range(len(matrix[0])) if y in used]
return cell_movement, trivial_cell


if __name__=="__main__":
print(row_walk(input()))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Joe
On Saturday, 9 April 2016 18:44:20 UTC+2, Ian  wrote:
> On Sat, Apr 9, 2016 at 8:18 AM, Joe  wrote:
> > How to find the number of robots needed to walk through the rectangular grid
> > The movement of a robot in the field is divided into successive steps
> >
> > In one step a robot can move either horizontally or vertically (in one row 
> > or in one column of cells) by some number of cells
> >
> > A robot can move in one step from cell X to cell Y if and only if the 
> > distance between the centers of the cells X and Y is equal to the sum of 
> > integers contained in X and Y
> >
> > Cell X is reachable for robot A if either A is currently standing in the 
> > cell X or A can reach X after some number of steps. During the transfer the 
> > robot can choose the direction (horizontal or vertical) of each step 
> > arbitrarily
> > [![enter image description here][1]][1]
> >
> > I started implementing it by first checking the row and print the index of 
> > the Cell X and Y where the distance is equal to the sum of integers 
> > contained in X and Y
> >
> > but after coding I found it difficult to remember the index when moving 
> > vertically
> >
> >  So I thought to Build a graph where nodes are grid cells and edges are 
> > legal direct movements, then run any connected components algorithm to find 
> > which cells are reachable from each other
> >
> >
> > Can anyone implement it with graphs or queue?
> 
> I'd use a disjoint-set data structure. The number of robots needed is
> equal to the number of disjoint subsets.
> 
> https://en.wikipedia.org/wiki/Disjoint-set_data_structure

Could you post a formal solution of disjoint-set using my algorithm  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Joe
On Saturday, 9 April 2016 21:24:02 UTC+2, Mark Lawrence  wrote:
> On 09/04/2016 18:13, Joe wrote:
> > On Saturday, 9 April 2016 18:44:20 UTC+2, Ian  wrote:
> >> On Sat, Apr 9, 2016 at 8:18 AM, Joe  wrote:
> >>> How to find the number of robots needed to walk through the rectangular 
> >>> grid
> >>> The movement of a robot in the field is divided into successive steps
> >>>
> >>> In one step a robot can move either horizontally or vertically (in one 
> >>> row or in one column of cells) by some number of cells
> >>>
> >>> A robot can move in one step from cell X to cell Y if and only if the 
> >>> distance between the centers of the cells X and Y is equal to the sum of 
> >>> integers contained in X and Y
> >>>
> >>> Cell X is reachable for robot A if either A is currently standing in the 
> >>> cell X or A can reach X after some number of steps. During the transfer 
> >>> the robot can choose the direction (horizontal or vertical) of each step 
> >>> arbitrarily
> >>> [![enter image description here][1]][1]
> >>>
> >>> I started implementing it by first checking the row and print the index 
> >>> of the Cell X and Y where the distance is equal to the sum of integers 
> >>> contained in X and Y
> >>>
> >>> but after coding I found it difficult to remember the index when moving 
> >>> vertically
> >>>
> >>>   So I thought to Build a graph where nodes are grid cells and edges are 
> >>> legal direct movements, then run any connected components algorithm to 
> >>> find which cells are reachable from each other
> >>>
> >>>
> >>> Can anyone implement it with graphs or queue?
> >>
> >> I'd use a disjoint-set data structure. The number of robots needed is
> >> equal to the number of disjoint subsets.
> >>
> >> https://en.wikipedia.org/wiki/Disjoint-set_data_structure
> >
> > Could you post a formal solution of disjoint-set using my algorithm
> >
> 
> You write the code, we comment on it.  No code, no comment.  Got the 
> message?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Sorry, I was desperate 
I deleted the post
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Joe
On Saturday, 9 April 2016 21:55:50 UTC+2, Mark Lawrence  wrote:
> On 09/04/2016 20:41, Joe wrote:
> >
> > Sorry, I was desperate
> > I deleted the post
> >
> 
> You didn't.  This will be showing in the archives in several places, e.g 
> https://mail.python.org/pipermail/python-list/2016-April/707160.html
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Well its still there, next time I'll not make the same mistake hopefully
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-15 Thread joe
John Bokma <[EMAIL PROTECTED]> writes:

> "David Schwartz" <[EMAIL PROTECTED]> wrote:
> > 
> > "Tim Roberts" <[EMAIL PROTECTED]> wrote in message 
> > news:[EMAIL PROTECTED]
> > 
> >> Part of their behavior really escape me.  The whole thing about
> >> browser wars confuses me.  Web browsers represent a zero billion
> >> dollar a year market.  Why would you risk anything to own it?
> > 
> > It really isn't that hard to understand that web-based
> > applications that work in any browser on any OS threaten
> > to make it irrelevent what OS you're running.
> 
> And it's even easier to understand that your statement is nonsense.
> 
> It doesn't matter which Linux distribution you pick, all use the Linux 
> kernel. On all I can run OpenOffice, and get the same results. Yet people 
> seem to prefer one distribution over one other.

He was talking about the browser war, and gave a pretty good reason
why it was important. So you respond by pointing out that people
choose a linux distribution for personal (non-technical,
non-marketing) reasons. I think I missed the connection.

> > MS has a strong interest in making sure it's important
> > to be running on one of their OSes.
> 
> Maybe *they* do have a point :-).

Which is?

Joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-15 Thread joe
John Bokma <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> 
> > John Bokma <[EMAIL PROTECTED]> writes:
> > 
> >> "David Schwartz" <[EMAIL PROTECTED]> wrote:
> >> > 
> >> > "Tim Roberts" <[EMAIL PROTECTED]> wrote in message 
> >> > news:[EMAIL PROTECTED]
> >> > 
> >> >> Part of their behavior really escape me.  The whole thing
> >> >> about browser wars confuses me.  Web browsers represent a zero
> >> >> billion dollar a year market.  Why would you risk anything to
> >> >> own it?
> >> > 
> >> > It really isn't that hard to understand that web-based
> >> > applications that work in any browser on any OS threaten to
> >> > make it irrelevent what OS you're running.
> >> 
> >> And it's even easier to understand that your statement is
> >> nonsense.
> >> 
> >> It doesn't matter which Linux distribution you pick, all use the
> >> Linux kernel. On all I can run OpenOffice, and get the same
> >> results.  Yet people seem to prefer one distribution over one
> >> other.
> > 
> > He was talking about the browser war, and gave a pretty good
> > reason why it was important. So you respond by pointing out that
> > people choose a linux distribution for personal (non-technical,
> > non-marketing) reasons. I think I missed the connection.
> 
> web based applications that work with any browser make OS irrelevant
> -> not true, since for OpenOffice it doesn't matter which Linux
> distribution one runs (or even if it's Linux), yet people seem to
> make a point of which distribution they use.

A linux distribution isn't an OS, it's a distribution, so I'm not sure
what your point here is.

In fact, there are lots of Microsoft-centric web pages that don't
work well when accessed from a linux system. ActiveX, MS Java, etc.

> >> > MS has a strong interest in making sure it's important
> >> > to be running on one of their OSes.
> >> 
> >> Maybe *they* do have a point :-).
> > 
> > Which is?
> 
> That it *does* matter. It doesn't matter which brand makes your
> graphics card, since most stick close to the reference design of the
> GPU chip supplier, yet people take the brand in consideration when
> they buy.

I don't think that's true, at least not yet. I recently bought a
Compaq Presario, which came with XP installed. I wiped the disk and
installed Linux, only to find that the hardware would only work under
XP. So I then had to install network, video, sound etc cards to get it
working.

joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-16 Thread joe
John Bokma <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> 
> > John Bokma <[EMAIL PROTECTED]> writes:
> > 
> >> [EMAIL PROTECTED] wrote:
> >> 
> >> > John Bokma <[EMAIL PROTECTED]> writes:
> >> > 
> >> >> "David Schwartz" <[EMAIL PROTECTED]> wrote:
> >> >> > 
> >> >> > "Tim Roberts" <[EMAIL PROTECTED]> wrote in message 
> >> >> > news:[EMAIL PROTECTED]

> >> web based applications that work with any browser make OS
> >> irrelevant -> not true, since for OpenOffice it doesn't matter
> >> which Linux distribution one runs (or even if it's Linux), yet
> >> people seem to make a point of which distribution they use.
> > 
> > A linux distribution isn't an OS, it's a distribution, so I'm not sure
> > what your point here is.
> 
> Ok, let me spell it out for you: If all your applications are web
> based, and the OS shouldn't matter, why do Linux distributions
> matter? It doesn't matter which one you use to run, for example,
> OpenOffice. Yet people pick a certain distribution. Why? Well, one
> reason is that people like to belong to a group. So even if it
> really doesn't matter which OS you are going to use to access a web
> application, or even which browser, people will pick a certain
> browser, and a certain OS, just because.

Thanks for spelling it out for me. Now could you spell out what this
has to do with Microsoft's intentions?

On second thought, don't bother, I think you're talking about
something else, and I'm not sure what that is.

Joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-18 Thread joe
"John W. Kennedy" <[EMAIL PROTECTED]> writes:

> Michael Heiming wrote:
> > Let's not forget about the Internet, they invented together with
> > Al Gore and of course the wheel!
> 
> No fair picking on Al Gore. All he ever claimed was that he was the
> Congressional point man for the "Information Superhighway", which he
> was.

Well, what he said was

  "During my service in the United States Congress, I took the
   initiative in creating the Internet."

What you say he did is what he actually did, but what he said gives a
different impression. I don't think he's careless or stupid, so I
think he said that in order to create the impression in the minds of
the people listening to the interview that he's responsible for the
internet. 

That's just what politicians do, regardless of party affiliation.

joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-18 Thread joe
"John W. Kennedy" <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> > "John W. Kennedy" <[EMAIL PROTECTED]> writes:
> >
> >>Michael Heiming wrote:
> >>
> >>>Let's not forget about the Internet, they invented together with
> >>>Al Gore and of course the wheel!
> >>
> >>No fair picking on Al Gore. All he ever claimed was that he was the
> >>Congressional point man for the "Information Superhighway", which he
> >>was.
> > Well, what he said was
> >   "During my service in the United States Congress, I took the
> >initiative in creating the Internet."
> > What you say he did is what he actually did, but what he said gives a
> > different impression. I don't think he's careless or stupid, so I
> > think he said that in order to create the impression in the minds of
> > the people listening to the interview that he's responsible for the
> > internet.
> 
> For "the Internet" as 99% of the American people comprehend it, he
> /was/ largely responsible, on the political end. The fact that the
> "Information Superhighway" turned out to be implemented as a massive
> explosion of the former ARPANet was an unforeseeable accident of
> history, resulting from the coincidental timing of the "Information
> Superhighway" initiative, the introduction of the Web, and (to some
> degree) the ARPANet worm.

This was said during an interview with Wolf Blitzer in 1999. By that
time the Internet was quite a bit more than ARPANet, and my guess is
that 99% of the American people thought of it as it was in 1999. His
comment created the impression that he was responsible for what
existed then.

Yes, he deserves credit for what he did. He nevertheless created a
false impression in what he said. If he hadn't created that false
impression, there would not have been any jokes about him. If all he
said was what he actually did, this would never have been an issue.

Joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


How to extract a part of html file

2005-10-19 Thread Joe
I'm trying to extract part of html code from a tag to a tag code begins
with   and ends with 
TD> http://whatever/some.gif";> 

I was thinking of using a regular expression however I having hard time
getting the desired string. I use 

htmlSource = urllib.urlopen("http://address/";)
s = htmlSource.read()
htmlSource.close()

to get the html into a string, now I want to match string s from a  http://whatever/some.gif";>  and
store that into a new string. 

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


Re: How to extract a part of html file

2005-10-20 Thread Joe
Thanks Mike that is just what I was looking for, I have looked at
beautifulsoup but it doesn't really do what I want it to do, maybe I'm
just new to python and don't exactly know what it is doing just yet.
However string find woks. Thanks

On Thu, 20 Oct 2005 09:47:37 -0400, Mike Meyer wrote:

> Ben Finney <[EMAIL PROTECTED]> writes:
> 
>> Joe <[EMAIL PROTECTED]> wrote:
>>> I'm trying to extract part of html code from a tag to a tag
>> For tag soup, use BeautifulSoup:
>> http://www.crummy.com/software/BeautifulSoup/>
> 
> Except he's trying to extract an apparently random part of the file.
> BeautifulSoup is a wonderful thing for dealing with X/HTML documents as
> structured documents, which is how you want to deal with them most of
> the time.
> 
> In this case, an re works nicely:
> 
>>>> import re
>>>> s = '  and ends with TD> >>> src="http://whatever/some.gif";> ' r =
>>>> re.match('(.*)TD> >>> src="http://whatever/some.gif";> ', s) r.group(1)
> '  and ends with '
>>>> 
>>>> 
> String.find also works really well:
> 
>>>> start = s.find('') + len('>>> class="boldyellow">') stop = s.find('TD> >>> src="http://whatever/some.gif";> ', start)
>>>> s[start:stop]
> '  and ends with '
>>>> 
>>>> 
> Not a lot to choose between them.
> 
> http://mail.python.org/mailman/listinfo/python-list


Re: IDE recommendation please

2005-10-22 Thread Joe

SPE is great I suggest you take a look at it 
http://www.stani.be/python/spe/

[EMAIL PROTECTED] wrote:
>> On the Mac, I think the XCode integration you get with PyObjC is
>> probably best.  I know there are plugins for Eclipse but haven't tried
>> any personally, so it's hard to make suggestions (I'm a dinosaur, and I
>> prefer to develop with GVim + a command-line tool, such as Python's own
>> interactive mode...).  I'm not sure if BlackAdder (simplest and fastest
>> to learn) and WingIDE (probably THE one most powerful Python IDE) work
>> on the Mac (shame on me, as a Python AND Mac enthusiast, for not having
>> tried them...), but they're surely worth investigating.  Ditto for
>> ActiveState's Komodo tool...
>> 
>> 
>> Alex

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


downloading web images

2005-10-22 Thread Joe
I'm just wandering if I'm doing this correct way I'm trying to download an
image and store it into a file this does the job, but created file does not
apear to be an image, it works fine and I can open image, I'm just
wandering if there is a better way of doing this. 

htmlSource=urllib.urlopen("http://www.godandscience.org/images/nebula.jpg";)
# Read from the object, storing the page's contents in 's'.
s = htmlSource.read()
htmlSource.close()
myfile = open("myfile.jpg", "w")
myfile.write(s)
myfile.close

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


how to count and extract images

2005-10-23 Thread Joe
I'm trying to get the location of the image uisng 

start = s.find('Save File',
start) fileName = s[start:stop]
and then construct the url with the filename to download the image 
which works fine as cause every image has the Save File link and I can
count number of images easy the problem is when there is more than image I
try using while loop downlaod files, wirks fine for the first one but
always matches the same, how can count and thell the look to skip the fist
one if it has been downloaded and go to next one, and if next one is
downloaded go to next one, and so on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-24 Thread joe
"David Schwartz" <[EMAIL PROTECTED]> writes:

> "Antoon Pardon" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
> >> Microsoft had something you need so badly that you could not go into
> >> business without it. So they demanded from you that you pay them what 
> >> their
> >> software was actually worth to you. That is not extortion. Everyone who
> >> sells something tries to get the maximum possible value for it.
> 
> > If a company wants to be paid for things it didn't deliver, then I think
> > that is extortion. Microsoft want te be paid a license on windows for
> > P.C.'s that were sold without windows.
> 
> I think you need to look up "extortion" in a dictionary. I can
> walk up to you and say "if you want me to mow your lawn, you must
> pay me $1 every time you smoke a cigarette". So long as you can say
> "no" and all that happens is that I don't mow your lawn (which I
> have no obligation to do anyway), it isn't extortion.

Extortion isn't the right word, of course. Nevertheless, being unable
to pay for a computer without also having to pay for an operating
system I don't want seems wrong to me.

Yes, I have alternatives, I generally buy components and put them
together myself. But why should I have to do that simply to avoid
paying  for an OS I'm not going to use?

The way this seems to work in practice strikes me as questionable at
best. Perhaps not illegal (IANAL so I don't know that) but certainly
one-sided. For one example, see

http://www.netcraft.com.au/geoffrey/toshiba.html

joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-25 Thread joe
Not Bill Gates <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote...
> 
> > 1) There is no other operating system worth selling. In this
> > case, you are right, you have no choice but to sell the Microsoft
> > OS, but the deal they're offering you harms you in no way. (Unless
> > you intended to sell PCs with no OS at all.)
> > 
> > 2) There are other realistic competing operating systems. In
> > this case, you were foolish to agree to Microsoft's deal. You lost
> > out on the realistic competing markets. That is, unless Windows
> > only really was a better deal, in which case you were wise to take
> > the deal and have no reason to be upset.
> 
> The flaw with this is that business owners don't get to decide what 
> the market wants.  And the market wanted the Microsoft OS.  Every 
> other OS in the market had bit player status, via the economic 
> principle called increasing returns. 
> 
> You either sell what the market wants, or you go out of business.

I'm hesitant to get into this, but I keep wondering why, if there is
no other competing OS, or not one worth worrying about, the MS
business agreements are so draconian? Why would a company come up with
such heavy handed agreements if it wasn't worried about competition?

Yes, I know, they can do whatever they want, it's not a crime,
etc. However when they use their market position to disallow
competition, it sounds to me like they're worried about something, and
trying to squelch it.

Joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-25 Thread joe
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Tue, 25 Oct 2005 09:56:28 -0500, joe wrote:
> 
> > Yes, I know, they can do whatever they want, it's not a crime,
> > etc. However when they use their market position to disallow
> > competition, it sounds to me like they're worried about something,
> > and trying to squelch it.
> 
> But that's the whole point: they *can't* do whatever they want,

They've been pretty much doing just that for a long time. The "it's
not a crime etc" part was to deflect parenthetical arguments that
confuse the issue. In other words, I was recognizing that a lot of
people don't think what MS does is a crime, and until MS gets
convicted of a crime, it's a matter of opinion. I was trying to say
something else.

> and certain behaviours *are* crimes. Just because Microsoft
> executives wear business suits instead of torn jeans or dirty
> sweatshirts doesn't make them beyond the law.

Maybe, but good lawyers might :-)

Joe
-- 
Gort, klatu barada nikto
-- 
http://mail.python.org/mailman/listinfo/python-list


PY2EXE => Is there a way to go backwards? EXE2PY

2005-07-13 Thread Joe
I have the executable of a script that I wrote, that has been erased.
Is there any way to retrieve the uncompiled python script from the
executable that was created with py2exe?

Thank you,


Joe

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


Re: Splitting on a word

2005-07-13 Thread Joe
# string s simulating an html file
s='ffy: ytrty python fyt wx  dtrtf'
p=re.compile(r'\bhref\b',re.I)

list=p.split(s)  #<<<<<<<<<<<<<<<<<   gets you your final list.

good luck,

Joe

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


Re: PY2EXE => Is there a way to go backwards? EXE2PY

2005-07-13 Thread Joe
Thank you, Peter.  Your point is well taken.  We a control system, but
I just never got around to using it.  I think now I'll get a round to
it. :)

Thanks again,

Joe

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


Bug Report / Patch (1159139 cgi.py invalid REQUEST_METHOD set)

2005-07-26 Thread Joe
Back in March I submitted a patch for cgi.py to sourceforge to fix a problem 
with the handling of an invalid REQUEST_METHOD.

I thought I followed all the steps to properly submit the bug and patch but 
the patch is still sitting there in limbo.

This is the first patch I have submitted for Python, did I miss a step in 
the patch process?

What else needs to be done?

Thanks!



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


Re: Bug Report / Patch (1159139 cgi.py invalid REQUEST_METHOD set)

2005-07-26 Thread Joe
Reinhold,

Thanks for responding...

I see that you are using Python 2.4.1 and the bug was against 2.4.  (I am 
now using 2.4.1)

If I remember correctly there were two issues that I ran into, one was with 
a missing REQUEST_METHOD and the other was with a INCORRECT request method. 
As per your example the missing one does not seem to be a problem any 
longer.

The incorrect REQUEST_METHOD setting still seems to be an issue with Python 
2.4.1.

Make the following changes to your code to demonstrate that problem.

import cgi
import os # NEW

os.environ['REQUEST_METHOD'] = 'cgi'# NEW

field = cgi.FieldStorage()

print field
print field.keys()# NEW

Run the program now with NO parameters. (I'm running on WinXP SP2).

After you start the program cgi.py will be reading from stdin.

type "a=1" and hit enter
type "b=2" and hit enter
press ctrl-z (to send eof) and hit enter

You will get the following stack trace.

FieldStorage(None, None, 'a=1\nb=2\n')
Traceback (most recent call last):
  File "H:\1\t2.py", line 12, in ?
print field.keys()
  File "P:\SW\Python\lib\cgi.py", line 601, in keys
TypeError: not indexable

When the environment does not have a correctly set REQUEST_METHOD cgi.py 
prompts
for key=value pairs by reading from sys.stdin.  (as demonstrated above)  I 
realize REQUEST_METHOD
should be set properly but hear me out.

After the values are read from sys.stdin they are never stored in the 
FieldStorage.list attribute like they are
when the FieldStorage.read_urlencoded or FieldStorage.read_multi methods are 
called.  The read_single
method is the one that has the problem (it is inconsistenty with the other 
two methods because it doesn't
store the values like the other two methods do).

This causes a problem when FieldStorage.keys() is called because although 
the values were read from
sys.stdin they were never stored in FieldStorage.list.

Although you could argue that REQUEST_METHOD should have been set correctly 
in the first place, it still
seems like if cgi.py is going to handle that situation of a invalid 
REQUEST_METHOD by actually reading the
values from sys.stdin (it already does this part) it should store them too 
(especially since it does store the values in the other two methods).

Does that explain the issue more clearly?


"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in 
message news:[EMAIL PROTECTED]
> Joe wrote:
>> Back in March I submitted a patch for cgi.py to sourceforge to fix a 
>> problem
>> with the handling of an invalid REQUEST_METHOD.
>>
>> I thought I followed all the steps to properly submit the bug and patch 
>> but
>> the patch is still sitting there in limbo.
>>
>> This is the first patch I have submitted for Python, did I miss a step in
>> the patch process?
>>
>> What else needs to be done?
>
> Can you provide an example script demonstrating the problem you describe?
>
> I tried something like this (Py2.4.1):
>
> --- test_cgi.py
> #!/bin/env python
> import cgi
> fs = cgi.FieldStorage()
> print fs
>
> $ python test_cgi.py "a=1&b=2"
> FieldStorage(None, None, [MiniFieldStorage('a', '1'), 
> MiniFieldStorage('b', '2')])
> $
>
> There's no REQUEST_METHOD or QUERY_STRING env var set.
>
> Reinhold 


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


Re: Jargons of Info Tech industry

2005-08-12 Thread joe
"Mike Schilling" <[EMAIL PROTECTED]> writes:

> "Jürgen Exner" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > Xah Lee wrote:
> >> Jargons of Info Tech industry
> >>
> >> (A Love of Jargons)
> >>
> >> Xah Lee, 2002 Feb
> >>
> >> People in the computing field like to spur the use of spurious
> >> jargons. The less educated they are, the more they like extraneous
> > [...]
> >
> > Just for the records at Google et.al. in case someone stumbles across 
> > Xah's
> > masterpieces in the future:
> > Xah is very well known as the resident troll in many NGs and his
> > 'contributions' are less then useless.
> 
> He sent a lovely one to some of the language groups the other day, 
> explaining why Jonathan Swift was a poor writer. 

That's remarkable, considering he doesn't realize "jargon" is a
collective noun.

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


Re: Jargons of Info Tech industry

2005-08-25 Thread joe
"Mike Schilling" <[EMAIL PROTECTED]> writes:

> "Rich Teer" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > On Thu, 25 Aug 2005, Mike Schilling wrote:
> >
> >> Another advantage is that evewry internet-enabled computer today
> >> already comes with an HTML renderer (AKA browser), so that a
> >> message saved to a file can be read very easily.
> >
> > I think you're missing the point: email and Usenet are,
> > historically have been, and should always be, plain text mediums.
> 
> Gosh, if you say they should be, there's no point trying to have an 
> intelligent discussion, is there?

Errm, isn't that what you're doing as well then? Rich just gave an
opinion, you've been giving an opinion. Rich's opinion happens to have
a lot of history and good reasons behind it. I don't see why it should
be viewed as some kind of discussion ending dogmatism.

Although it might not be bad if this discussion ended :-)

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


Re: Jargons of Info Tech industry

2005-08-25 Thread joe
"T Beck" <[EMAIL PROTECTED]> writes:

> Mike Schilling wrote:
> > "Rich Teer" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > On Thu, 25 Aug 2005, Mike Schilling wrote:
> > >
> > >> Another advantage is that evewry internet-enabled computer
> > >> today already comes with an HTML renderer (AKA browser), so
> > >> that a message saved to a file can be read very easily.
> > >
> > > I think you're missing the point: email and Usenet are,
> > > historically have been, and should always be, plain text
> > > mediums.
> >
> > Gosh, if you say they should be, there's no point trying to have an
> > intelligent discussion, is there?
> 
> Not to mention that e-mail is practically to the point where it is
> {not} a plain text medium.  I notice this especially in a corporate
> environment (where, at least where I work, I get at least 10 times the
> number of e-mails at work than I do on my private account) HTML e-mail
> is the de-facto standard.  I have a tendancy to send out plain text
> e-mail, and I'm practically the only one, as HTML formatting is the
> default for the mail client on every corporate machine at my job.

If you're using exchange for email servers it might be reformatting
mail sent as plain text anyway. Waste of bandwidth.

> But let's not forget that most people which send me e-mail personally
> also have HTML tags in e-mail...  So if e-mail {is} a plain text
> medium, somebody needs to tell the general public, because I think they
> must've missed a memo.
> 
> If we argue that people are evolving the way e-mail is handled, and
> adding entire new feature sets to something which has been around since
> the earliest days of the internet, then that's perfectly feasable.
> HTML itself has grown.  We've also added Javascript and Shockwave.  The
> websites of today don't even resemble the websites of 10 years ago,
> e-mail of today only remotely resembles the original, so the argument
> that usenet should never change seems a little heavy-handed and
> anachronistic.

That's a good point, but just because things are evolving doesn't mean
they're making more sense. Html does waste bandwidth, it does open up
avenues for malware that text mail doesn't, etc.

It seems to me that any intelligent person has to turn off so many
"features" in html mail clients that they lose many of what are seen
of as advantages.

I suspect I either missed some of this thread or I'm misunderstanding
some of it. If what the OP was trying to suggest was a more confined
form of html, say, something that doesn't allow links, I'd consider
that a good thing. I doubt anyone will use it though, I think MS wants
all the bells and whistles, and all the embracing and extending it can
do. If they don't support such an html subset for email I suspect it
won't go anywhere.

But why bother? An html subset that takes everything away but
formatting sounds pretty much like what I'm doing right now with
gnus. 

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


Re: Big development in the GUI realm

2005-02-08 Thread Joe
On Tue, 8 Feb 2005 10:01:51 +0100, "Fredrik Lundh"
<[EMAIL PROTECTED]> wrote:
>except that if *you* set things up so the code is combined when run, *you* are
>copying, distributing, and/or modifying the program in order to mix, include 
>and/or
>combine your work with the GPL:ed work.
>
>if you leave all that to the user, you're clear.

Mmm... I'm not playing games here, no matter what some seem to think. 

It's obvious that the GPL doesn't say precisely whether it's OK to use
an _independent_ library or EXE, ie. a file that is physically
different from the calling EXE, as oppposed to either copy/pasting the
code as is into a program, or statically linking a library into an
EXE.

Until now, I understood the GPL to be a way to make sure no one stole
code (hence, no static linking or copy/pasting code), and with or
without giving back any change they made.

OTOH, I though it was OK to use the by code shipping whatever standard
binary file was downloaded from the project's site, ie. MYEXE.EXE
calling YOURCODE.DLL was OK, when this code was the standard version,
untampered, and clearly indicated as not the EXE's work (as shown by
the file name and version infos).

Hence, either the GPL was not precise enough, or TrollTech should use
a different license that specifically prohibits even using Qt through
dynamic linking.

Conclusion from what I read above: As of now, no court in any country
has settled this issue by specifying whether making use of a GPLed
program _in any way_ requires the calling program to be GPLed as well,
or if there are cases where the EXE can remain closed-source. I'm fine
with TT's intentions, though.

Joe
(no, I don't want whatever stuff I post on the Net to possibly bite me
years from now, hence the anonymous posting. Nothing personal.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ZoDB's capabilities

2005-02-28 Thread Joe
On Mon, 28 Feb 2005 23:31:27 +0100, Almad <[EMAIL PROTECTED]> wrote:
>I'm going to write a custom CMS. I'd like to use some odbms, as code is then
>much more cleaner...

You should go ask for pratical infos on ZODB here:

http://www.zope.org/Products/StandaloneZODB

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


What is the best way to handle a command line argument that includes an escape sequence like \n?

2005-03-02 Thread Joe
I'm using Python 2.4 on Windows XP SP2.

I'm trying to receive a command line argument that is a newline (\n)

Here is the command line to use

sample.py "\n"

Here is a sample.py script

import sys

c = sys.argv[1]

# when run c is set to \\n instead of \n.

I created a test batch file

echo %1

to confirm that it was not the cmd.exe command processor causing the issue.

It appears that Python treats the comand line string as a raw string.

Is this a bug?  If not what is the best way to work around the issue?

Obviously I could use a hack

if c == '\\n':
c = '\n'

But surely there is a better way.

NOTE that I used \n in my sample but I also want to support other escape 
sequences too.



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


mx.ODBC 2.0.7 bug?

2005-03-02 Thread Joe
Python 2.4
Windows XP SP2
MS Access 2000
mx.ODBC 2.0.7

Problem data truncation occuring (here's the actual error message):

mxODBC.Warning: ('01004', 5, '[Microsoft][ODBC Microsoft Access Driver] 
String data, right truncated on column number 3 (Expr1002)', 3326)

I believe that  have found a bug in mx.ODBC not properly assigning the 
correct data type to a column.

Here is a sample script that demonstrates the problem and why I think it is 
being handled incorrectly:

# NOTE memo1 and memo2 are memo fields in the test_table

import mx.ODBC.Windows

dbs = mx.ODBC.Windows.connect('database', '', '')

sql = "select memo1, memo2, memo1 & ' ' & memo2 from test_table where 
record_id = 1"

c   = dbs.cursor()

c.execute(sql)

print
print 'mxODBC SQL DataTypes:'
print

for i in mx.ODBC.Windows.sqltype:
print i, mx.ODBC.Windows.sqltype[i]

print
print 'Column DataTypes:'
print

for i in range(len(c.description)):
print c.description[i][1]

c.close()
dbs.close()

When you run this script it produces the following output:

mxODBC SQL DataTypes:

1 CHAR
2 NUMERIC
3 DECIMAL
4 INTEGER
5 SMALLINT
6 FLOAT
7 REAL
8 DOUBLE
9 DATE
10 TIME
11 TIMESTAMP
12 VARCHAR
91 TYPE_DATE
92 TYPE_TIME
93 TYPE_TIMESTAMP
-1 LONGVARCHAR
-10 WCHAR_LONGVARCHAR
-9 WCHAR_VARCHAR
-8 WCHAR
-7 BIT
-6 TINYINT
-5 BIGINT
-4 LONGVARBINARY
-3 VARBINARY
-2 BINARY

Column DataTypes:

-1
-1
12

>From the output you can see that memo1 and memo2 are both determined to be 
of type longvarchar (-1) but when the columns are concatenated together the 
resulting column is given a type of varchar (12).  Obviously this is why the 
data truncation is occurring.

Is this a known problem?

I can work around the problem using a converter function:

def converter(position, sqltype, sqllen):
print 'in :', position, sqltype, sqllen
if position == 2:
sqltype = -1
sqllen  = 1073741823
print 'out:', position, sqltype, sqllen
return sqltype, sqllen

and then using:

c.setconverter(converter)

but shouldn't mx.ODBC have properly assigned the correct sqltype and sqllen 
for the concatenated memo columns in the first place?

















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


Re: What is the best way to handle a command line argument that includes an escape sequence like \n?

2005-03-02 Thread Joe
Steve,

THANKS!  That is exactly what I was looking for but unable to find.

Joe

"Steven Bethard" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Joe wrote:
>> It appears that Python treats the comand line string as a raw string.
>>
>> what is the best way to work around the issue?
>
> You probably want to use str.decode with the encoding 'string_escape'[1]
>
> py> s = r'\n\t'
> py> s
> '\\n\\t'
> py> s.decode('string_escape')
> '\n\t'
>
> STeVe
>
> [1]http://docs.python.org/lib/standard-encodings.html 


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


Re: What is the best way to handle a command line argument that includes an escape sequence like \n?

2005-03-03 Thread Joe
Hi Steve,

I've been using Python for many years, just hadn't had to deal with an 
escape sequence in the command line args. :-) and couldn't find the solution 
in the docs.

It is easy to prove my assertion:

import sys
c = sys.argv[1]
print len(c)
print 'Line 1', c, 'Line 2'

Output:
2
Line 1 \n Line 2

Versus:

import sys
c = sys.argv[1]
print len(c)
print 'Line 1', c.decode('string_escape'), 'Line 2'

Output:
2
Line 1
Line 2

Agreed, it is much easier on Unix to deal with this, I have not seen a way 
to get the XP command interpreter to allow a multiline command line as you 
described.

Your solution was exactly what I need.  I had an escape sequence entered on 
the command line and needed to decode the string so that Python used it as 
an escape sequence, in fact the sequence really is part of the output that 
the program produces.

Thanks again for your assistance.

Regards,

Joe

> I don't want you getting more confused rather than less - newcomers are 
> sometimes confused by Python's encoding of backslashes and such when 
> printing out strings. What is your evidence for the assertion that c is 
> set to \\n rather than \n?
>
> In Unix, it's easier to avoid this, since the shell lets you enter 
> multi-line strings (note that these lines may wrap in the mail):
>
> [EMAIL PROTECTED] sholden]$ python -c "import sys; print repr(sys.argv[1])" 
> "\n"
> '\\n'
> [EMAIL PROTECTED] sholden]$ python -c "import sys; print repr(sys.argv[1])" 
> "
> > "
> '\n'
>
> The first case simply demonstrates that the shell doesn't interpret 
> backslash escape sequences. I used repr() because that's what the 
> interpreter will print if you enter an expression at the interactive 
> prompt. The first case shows that the argument is two characters - you can 
> verify this using the len() function.
>
> The second case shows how (with a sensible command shell) you can provide 
> a newline as an argument.
>
> In Windows we can emulate the first case exactly:
> C:\Steve>C:\python24\python -c "import sys; print repr(sys.argv[1])" "\n"
> '\\n'
>
> Unfortunately Windows XP's command interpreter doesn't bother to wait 
> until you close a double-quote left open at the end of a line:
>
> C:\Steve>\python24\python -c "import sys; print repr(sys.argv[1])" "
> ''
>
> So someone else will have to tell you how to do that, but you should be 
> clear about what's happening before you try and correct the problem.
>
> regards
>  Steve
> -- 
> Meet the Python developers and your c.l.py favorites March 23-25
> Come to PyCon DC 2005  http://www.pycon.org/
> Steve Holden   http://www.holdenweb.com/ 


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


Re: What is the best way to handle a command line argument that includes an escape sequence like \n?

2005-03-03 Thread Joe
Antoon,

I tested the batch file :-)

The one line batchfile does prove it because it prints out  
and not .

See other post, decode is exactly what was needed to fix the problem.

Regards,

Joe

"Antoon Pardon" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Op 2005-03-02, Joe schreef <[EMAIL PROTECTED]>:
>> I'm using Python 2.4 on Windows XP SP2.
>>
>> I'm trying to receive a command line argument that is a newline (\n)
>>
>> Here is the command line to use
>>
>> sample.py "\n"
>
> Are you sure this supplies a newline and not the string  
>
>> Here is a sample.py script
>>
>> import sys
>>
>> c = sys.argv[1]
>>
>> # when run c is set to \\n instead of \n.
>>
>> I created a test batch file
>>
>> echo %1
>>
>> to confirm that it was not the cmd.exe command processor causing the 
>> issue.
>
> I'm not sure this confirms anything. IMO it is possible that echo
> will translate   to , giving you the
> impression that you have provideded a newline on the command line
> while in fact you have not.
>
> -- 
> Antoon Pardon 


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


Re: mx.ODBC 2.0.7 bug?

2005-03-03 Thread Joe
Hi Steve,

Thanks, I find you get much better help when you provide the details needed 
for your case instead of expecting others to invest alot of their time 
before you did your homework.

Thanks for sending it over to Marc.  Last time I found a bug in the mx stuff 
(YEARS AGO) I sent it directly to Marc but was trying not to bother him 
until I tried the list first.

One point I forgot to mention in the previous reply is that AFTER the 
converter function is setup and used if you examine the 
cursor.description[column][1] values it still has the old sqltype and 
sqllen.  Not sure if that would be considered a bug or not?  I would have 
expected that the converter hook would have also modified the description 
info to match what the converter hook did.

Thanks again for your assistance.

Regards,

Joe


> This is a very nice piece of deduction, and I am copying this message to 
> you and to the egenix-users list, since that's generally a reliable way to 
> get Marc-Andre's attention.
>
> I'm not convinced that it demonstrates an mxODBC bug, since I don't 
> believe that the ampersand is actioned by the drivers, but I'm not the 
> best one to be authoritative about this.
>
> others-who-read-this-reply-will-ly y'rs  - steve
> -- 
> Meet the Python developers and your c.l.py favorites March 23-25
> Come to PyCon DC 2005  http://www.pycon.org/
> Steve Holden   http://www.holdenweb.com/ 


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


Re: What is the best way to handle a command line argument that includes an escape sequence like \n?

2005-03-03 Thread Joe
Hey no fair changing last names in the middle of a thread :-)

Thanks to BOTH Steve's.


> In fairness it was Steven Bethard's solution that gave you the solution 
> you needed. As long as ytour problem is solved, that's fine, and it 
> appears that you've solved it in a reasonably cross-platform way.
>
> Steve Holden   http://www.holdenweb.com/ 


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


python -i (interactive environment)

2005-03-06 Thread Joe
When you run "python -i scriptname.py" after the script completes you left 
at the interactive command prompt.

Is there a way to have this occur from a running program?

In other words can I just run scriptname.py (NOT python -i scriptname.py) 
and inside of scriptname.py I decide that I want to fall back to the 
interactive prompt?

I've searched and so far the only thing I've come up with is to use pdb, but 
that is not exactly the same as the interactive prompt.

Is there any way to do it that I have missed?

Thanks. 


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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Hi Pierre,

Thanks for the reply, but  I am not on Unix and it even if I was that 
solution it does not achieve the desired results.

I want the script to decide whether to fall back to the interactive prompt. 
You solution makes it ALWAYS fall back to the interactive prompt.

I want to do something like:

try:
# execute code
except MyExceptionOccurred, except_msg:
# fall to interactive prompt.

In other words I want to have my program to determine whether the 
interactive prompt to be displayed or not.

Thanks!


"Pierre Barbier de Reuille" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Very simple is you're on UNIX ...
>
> You juste have to put at the beginnin of your file :
>
> #!/usr/bin/python -i
>
> And it juste does what you want :)
>
> Pierre
>
> Joe a écrit :
>> When you run "python -i scriptname.py" after the script completes you 
>> left at the interactive command prompt.
>>
>> Is there a way to have this occur from a running program?
>>
>> In other words can I just run scriptname.py (NOT python -i scriptname.py) 
>> and inside of scriptname.py I decide that I want to fall back to the 
>> interactive prompt?
>>
>> I've searched and so far the only thing I've come up with is to use pdb, 
>> but that is not exactly the same as the interactive prompt.
>>
>> Is there any way to do it that I have missed?
>>
>> Thanks. 


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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Thanks Michael, that's what I was looking for.

Are there any differences between that and the actual interactve prompt that 
I should be aware of?

Would you consider that a better method than using (thanks to those who 
suggested this other option):

import os
os.environ['PYTHONINSPECT'] = '1'


"Michael Hoffman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Joe wrote:
>
>> I want the script to decide whether to fall back to the interactive 
>> prompt. You solution makes it ALWAYS fall back to the interactive prompt.
>
> Actually, using sys.exit() means the program can exit even if python -i
> is used.
>
> You can use:
>
> import code
> code.interact()
>
> which emulates the interactive prompt.
> -- 
> Michael Hoffman 


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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Reinhold,

Interesting.

A key difference between the two is that PYTHONINSPECT will allow you access 
to the prompt at the end of your program (assuming no sys.exit or raise 
SystemExit) but code.interact() allows you to jump into the program at any 
point.


"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in 
message news:[EMAIL PROTECTED]

>   /* Check this environment variable at the end, to give programs the
>* opportunity to set it from Python.
>*/
>
> Reinhold 


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


Re: python -i (interactive environment)

2005-03-06 Thread Joe
Funny you said that, because I didn't even bother trying it because I didn't 
think it would work either.  I figured that python did something internally 
when it saw the -i switch.  Looks like it just checks for it when it's done 
with your code.

One difference between the two methods that I see is that when you set 
PYTHONINSPECT you don't really have to do anything else and unless 
sys.exit() or raise SystemExit is used you will get the interactive prompt.

Using code.interact you would need to wrap everything in a try/except block 
and call code.interact from there, or you could invoke it whenever you 
wanted too.  This has the advantage that you can even trap SystemExit if you 
want too.

Thanks again to everyone!


"Michael Hoffman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Joe wrote:
>
> Actually I would do that everyone else suggested for your use case. I 
> thought
> about trying this method but couldn't imagine that it would actually work!
> -- 
> Michael Hoffman 


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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Found that out :-(

You can use the local=locals() option so at least you have access to the 
local variables, which in the case of debugging, is exactly what I needed.

Since -i gives you control at the end of the program the locals are already 
gone.

Seems like both approaches have their advantages depending on the situation.

"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Unfortunately it does so in an entirely new namespace, thereby losing the 
> advantage of -i - namely, that you can investigate the program's namespace 
> after it's terminated.


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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Right, but only one namespace.  Would be nice if there was a way to give it 
both the global and the local namespaces.  In my case though the local 
namespace was sufficient.

"Just" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> code.interact() has a namespace argument ('local'), so it really easy to
> have it use the namespace you want.
>
> Just 


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


cgi.py bug

2005-03-08 Thread Joe
While debugging a problem I was having I found a bug in the cgi.py module.

When the environment does not have a correctly set REQUEST_METHOD cgi.py 
prompts
for key=value pairs by reading from sys.stdin.  After the values are read 
from
sys.stdin they are never stored in the FieldStorage.list attribute like they 
are
when the FieldStorage.read_urlencoded or FieldStorage.read_multi methods are 
called.

This causes a problem when FieldStorage.keys() is called because although 
the values
were read from sys.stdin they were never stored in FieldStorage.list.

Although you could argue that REQUEST_METHOD should have been set correctly 
in the
first place, it still seems like if cgi.py is going to handle that situation 
by
actually reading the values from sys.stdin it should store them too.

It "appears" that this can fixed by modifying the read_single method of 
FieldStorage to store
the lines read from sys.stdin just like the other two methods do.

Here is the fix that I proposed that seems to address the problem.

def read_single(self):
"""Internal: read an atomic part."""
if self.length >= 0:
self.read_binary()
self.skip_lines()
else:
self.read_lines()
self.file.seek(0)

# Joe's fix
lines = '&'.join([line.rstrip('\n') for line in 
self.file.readlines()])
self.file.seek(0)

self.list = list = []

for key, value in parse_qsl(lines, self.keep_blank_values,
self.strict_parsing):
list.append(MiniFieldStorage(key, value))
# End of Joe's fix

I have tested the fix using a few different combinations and also with an 
immediate EOF and it seems to work in
all cases that I have test.

The bug has been reported on Sourceforge and I submitted the above patch.


















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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Isn't this a bug?

Here's the test program:

import code

def test_func():
lv = 1
print '\n\nBEFORE lv: %s\n' % (lv)
code.interact(local=locals())
print '\n\nAFTER  lv: %s\n' % (lv)
return

test_func()

gv = 1
print '\n\nBEFORE gv: %s\n' % (gv)
code.interact(local=locals())
print '\n\nAFTER  gv: %s\n' % (gv)

Here's the output and interactive session:



BEFORE lv: 1

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> lv = 2
>>> print lv
2
>>> ^Z



AFTER  lv: 1



BEFORE gv: 1

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> gv = 2
>>> print gv
2
>>> ^Z



AFTER  gv: 2

In the case of code.interact being called inside the function, the locals 
were available to the interactive environment but changes did not stick when 
you returned back the function. (started as lv=1 changed to lv=2 in 
interactive session, back to lv=1 in function)  Since you are still in the 
function and since code.interact used the same local environment why didn't 
the change stick until testfunc ended?

When code.interact was called from the outside the function (globals() == 
locals()) the changes stuck. (started as gv=1, changed to gv=2 in 
interactive session, stuck as gv=2 back in main).





"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Michael Hoffman wrote:
>> Joe wrote:
>>
>>> I want the script to decide whether to fall back to the interactive 
>>> prompt. You solution makes it ALWAYS fall back to the interactive 
>>> prompt.
>>
>>
>> Actually, using sys.exit() means the program can exit even if python -i
>> is used.
>>
>> You can use:
>>
>> import code
>> code.interact()
>>
>> which emulates the interactive prompt.
>
> Unfortunately it does so in an entirely new namespace, thereby losing the 
> advantage of -i - namely, that you can investigate the program's namespace 
> after it's terminated.
>
> regards
>  Steve
> 


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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Steve,

Thanks, I knew about that but my question is why is it not working 
consistently?

Joe


"Steven Bethard" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Joe wrote:
>> Isn't this a bug?
>>
>> Here's the test program:
>>
>> import code
>>
>> def test_func():
>> lv = 1
>> print '\n\nBEFORE lv: %s\n' % (lv)
>> code.interact(local=locals())
>> print '\n\nAFTER  lv: %s\n' % (lv)
>> return
>
> Check the documentation for locals() [1]:
>
> "Update and return a dictionary representing the current local symbol 
> table. Warning: The contents of this dictionary should not be modified; 
> changes may not affect the values of local variables used by the 
> interpreter."
>
> So if you change things in the dictionary returned by locals() you won't 
> actually change the local variables.
>
> STeVe
>
> [1] http://docs.python.org/lib/built-in-funcs.html#l2h-45 


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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Thanks I thought that was also true for globals() but I now see that it is 
not.

"Steven Bethard" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Joe wrote:
>> Thanks, I knew about that but my question is why is it not working 
>> consistently?
>
> At the module level, locals() is globals():
>
> py> locals() is globals()
> True
>
> And the globals() dict is modifiable.
>
> HTH,
>
> STeVe 


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


Re: Working on a log in script to my webpage

2005-03-11 Thread Joe
Pete,

What web server are you using?

Take a look at Apache and use digest authentication.  The password is not 
sent in clear text and it's fairly easy to setup.  Plus you won't have to do 
anything in your web pages.  Once you setup digest authentication on the web 
server for the specified directories, the user will be prompted by their 
browser for the user / pswd and as long as the directories they access are 
using the same authentication the user will not be prompted again until they 
close their session.

It's pretty easy to setup.

Joe

"Pete." <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi all.
>
> Unfortunaly it looks like I dont have to skill to make a secure log in, 
> cant figure out how the code has to look like, so guess my webpage has to 
> live with a security issue.
>
> Thanks for the effort you put into teaching me the use of cookies.
>
> Best wishes
> Pete
>
> "Pete." <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Thanks.
>>
>> But I would really like to do this from scratch, so that I can learn it, 
>> I dont think I need that much more, before it works.
>>
>> I found an example with asp, where the save the session if the password 
>> is correct. It isnt that long a code, so was wondering if it isnt 
>> possible to make something like that in python. Cause when this code is 
>> applied to the loginform, CODE2 will only have to be applied to every 
>> following page and everything is good.
>>
>> code is from: 
>> http://tutorialized.com/tutorial/Creating-a-Members-Area-in-ASP/2234
>> CODE1
>> Set objRS = objConn.Execute (strSQL)
>>  '// see if there are any records returned
>>  If objRS.EOF Then
>>  'no username found
>>  strError = "- Invalid username or password" & vbNewLine
>>  Else
>>  'check password
>>  If objRS("password")=Request.Form("password") Then
>>   'username/password valid
>>   'save session data
>>   Session("loggedin") = True
>>   Session("userid") = objRS("id")
>>   'redirect to members area
>>   Response.Redirect ("default.asp")
>>   Response.End
>>  Else
>>   'invalid password
>>   strError = "- Invalid username or password" & vbNewLine
>>
>> CODE2<%
>> If Session("loggedin") <> True Then Response.Redirect "login.asp"
>> %>
>> 
>> 
>> Members Area
>> 
>> 
>> Members Area
>> Welcome to our members area!
>>  In my code I have allready tested if the username and password is 
>> correct, so I just need to do the cookie thing :D
>>
>> Thanks all, hope all my questions dosnt make you tired, I just really 
>> wanna figure this out, and I am doing this as a little hobby of mine, so 
>> I dont have anyone else to ask, hope that is okay...
>>
>>
>>
>> "Kent Johnson" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>> Pete. wrote:
>>>> Hi all I am working on a log in script for my webpage.
>>>>
>>>> I have the username and the password stored in a PostgreSQL database.
>>>
>>> You might want to look at Snakelets and CherryPy.
>>>
>>> Snakelets is "a very simple-to-use Python web application server." One 
>>> of the features is "Easy user authentication and user login handling."
>>> http://snakelets.sourceforge.net/
>>>
>>> CherryPy is "a pythonic, object-oriented web development framework" that 
>>> seems to be popular. A recipe for password-protected pages in CherryPy 
>>> is here:
>>> http://www.cherrypy.org/wiki/PasswordProtectedPages
>>>
>>> Kent
>>
>>
>
> 


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


Re: Web framework

2005-03-13 Thread Joe
On 13 Mar 2005 01:13:00 -0800, [EMAIL PROTECTED] wrote:

>You should definitely have a look at Zope 3. There is good
>documentation available and it can do a lot of good stuff.

But then, the thing I hate about Zope, is that source code is not
accessible with normal development tools since it's stuck in the ZODB.

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


Re: Web framework

2005-03-14 Thread Joe
On Sun, 13 Mar 2005 19:20:34 +0100, "Diez B. Roggisch"
<[EMAIL PROTECTED]> wrote:
>Plain wrong. You can access them via FTP and WEBDAV.

Not wrong. I am aware of this, but it's not like that many development
tools can work through FTP or WebDav... Besides, how to have the
source code under source control if it's stuck in the ZODB?

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


Re: Web framework

2005-03-14 Thread Joe
On Mon, 14 Mar 2005 11:18:10 +0100, Josef Meile <[EMAIL PROTECTED]>
wrote:
>I guess you are reffering to "Python Scripts" and "ZClasses", which
>indeed are stuck in the ZODB. But in fact you can write external python
>products for zope, which reside on your file system. What is stuck in
>the ZODB would be the instances of those products.

Right, but it's still a pain. Incidently, this is the reason for
Zope-inspired frameworks like CherryPy, ie. Zope with ol' fashioned
dev tools.

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


Re: Web framework

2005-03-15 Thread Joe
On Tue, 15 Mar 2005 00:07:34 -0500, Benji York <[EMAIL PROTECTED]>
wrote:
>That's not entirely true of Zope 2, and not true at all for Zope 3.  All 
>code for Zope 3 is loaded from the file system.

Great news :-) I'll go check it out.

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


Re: Is Python like VB?

2005-03-17 Thread Joe
On Wed, 16 Mar 2005 21:33:36 -0800, "Mike Cox"
<[EMAIL PROTECTED]> wrote:
>Where I work we use  Microsoft Office with a lot of customization using
>Visual Basic.  I would like to switch to Python to do it since VB is being
>discontinued.  Would Python meet our requirements? I need to make lots of
>GUI applications (message boxes, forms, etc.) and do the underlying business
>logic too.

I wouldn't advise you to switch to Python from VB if...
1. the installer must be downloaded from the Net, so must be kept as
small as possible (GUI layers like wxWidgets of PyGTK add several
megabytes to your app)
2. you're used to sophisticated GUI designers like VB or Delphi, and
want something as polished
3. you expect an IDE as rich as those two proprietary tools (including
IntelliSense, intigrated GUI designer, compiler, etc.)
4. your app uses third-party components that are not available to
platforms other than VB (or Delphi)

After checking out the tools currently available, I got to the
conclusion that Python is a very fine tool for text-based apps or
moderately-sophisticated GUI apps like BitTorrent.

For more demanding GUI apps, I would advise you stick to VB until the
.Net framework stabilizes and trickles down to being available on 80%
of hosts, at which point you can safely trade horses (VB.Net does
solve some of the oddities of VB Classic.)

In an ideal world, we'd have open-source development tools as rich as
VB or Delphi, but at this point, I haven't found any that doesn't fall
short on any of the points above (probably because the work involved
is underevaluated, and just not doable without a constant and
sufficient revenue stream.)

Just my opinion,
Joe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python like VB?

2005-03-18 Thread Joe
On Thu, 17 Mar 2005 22:02:48 -0800, Tim Roberts <[EMAIL PROTECTED]>
wrote:
>Why on earth would
>you choose to reimplement your software in a different language, rather
>than just do the simple version upgrade?

A lot of developers and companies are pondering this issue. The
end-of-lifing of Classic VB is a wake-up call for many, who take this
opportunity to check whether it's a good idea to keep using
proprietary tools which can be discontinued any time if the
manufacturer figures he can get away with forcing his customers to
upgrade.

>From there, it's like playing the stock exchange: Is it more risky and
financially sound to follow Microsoft and switch from VB Classic to
VB.Net, or to jump ship, and use open-source solutions?

At this point, I would advise the OP, if possible, to just keep
working on the Classic VB version of his application while developing
small side-projects in VB.Net to master this new language/tool, and
once 80% of hosts have the .Net framework, it'll be time to check
which route seems more promising.

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


Re: Python/wxPython Reducing memory usage.

2005-04-09 Thread Joe
On 8 Apr 2005 23:35:57 -0700, "lotmr" <[EMAIL PROTECTED]> wrote:
>Is there any way that I could compile or optimize the my program and/or its 
>memory usage?

... and ideally, if we could also reduce the size of the DLL, so that
it would only include the widgets actually used, it'd be even nicer.

>(Note: I don't have a problem with making this program win32 specific,
>as it already is only win32)

I don't have much experience with it, but is the PythonWin wrapper to
MFC horrible to use as compared to wxWidgets? If it's good enough and
you don't care about non-Windows platforms, you'll probably save a lot
of RAM and file footprint.

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


Re: Python Unicode handling wins again -- mostly

2013-12-02 Thread joe
How would a grapheme library work? Basic cluster combination, or would
implementing other algorithms (line break, normalizing to a "canonical"
form) be necessary?

How do people use grapheme clusters in non-rendering situations? Or here's
perhaps here's a better question: does anyone know any non-latin (Japanese
and Arabic come to mind)  speakers who use python to process text in their
own language? Who could perhaps tell us what most bugs them about python's
current api and which standard libraries need work.
On Dec 2, 2013 10:10 PM, "Steven D'Aprano"  wrote:

> On Mon, 02 Dec 2013 16:14:13 -0500, Ned Batchelder wrote:
>
> > On 12/2/13 3:38 PM, Ethan Furman wrote:
> >> On 11/29/2013 04:44 PM, Steven D'Aprano wrote:
> >>>
> >>> Out of the nine tests, Python 3.3 passes six, with three tests being
> >>> failures or dubious. If you believe that the native string type should
> >>> operate on code-points, then you'll think that Python does the right
> >>> thing.
> >>
> >> I think Python is doing it correctly.  If I want to operate on
> >> "clusters" I'll normalize the string first.
> >>
> >> Thanks for this excellent post.
> >>
> >> --
> >> ~Ethan~
> >
> > This is where my knowledge about Unicode gets fuzzy.  Isn't it the case
> > that some grapheme clusters (or whatever the right word is) can't be
> > normalized down to a single code point?  Characters can accept many
> > accents, for example.  In that case, you can't always normalize and use
> > the existing string methods, but would need more specialized code.
>
> That is correct.
>
> If Unicode had a distinct code point for every possible combination of
> base-character plus an arbitrary number of diacritics or accents, the
> 0x10 code points wouldn't be anywhere near enough.
>
> I see over 300 diacritics used just in the first 5000 code points. Let's
> pretend that's only 100, and that you can use up to a maximum of 5 at a
> time. That gives 79375496 combinations per base character, much larger
> than the total number of Unicode code points in total.
>
> If anyone wishes to check my logic:
>
> # count distinct combining chars
> import unicodedata
> s = ''.join(chr(i) for i in range(33, 5000))
> s = unicodedata.normalize('NFD', s)
> t = [c for c in s if unicodedata.combining(c)]
> len(set(t))
>
> # calculate the number of combinations
> def comb(r, n):
> """Combinations nCr"""
> p = 1
> for i in range(r+1, n+1):
> p *= i
> for i in range(1, n-r+1):
> p /= i
> return p
>
> sum(comb(i, 100) for i in range(6))
>
>
> I'm not suggesting that all of those accents are necessarily in use in
> the real world, but there are languages which construct arbitrary
> combinations of accents. (Or so I have been lead to believe.)
>
>
> --
> Steven
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Indentation/whitespace

2005-12-23 Thread Joe
Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python's syntax makes sense. There are strong
feelings both ways. It must depend on a person's way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don't learn to like it,
but instead just learn to live with it.

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


Re: Indentation/whitespace

2005-12-24 Thread Joe
My original post was based on reading on Pythons developer list that it
was seriously considering some alternate grouping scheme, just because
"so many people keep asking". But, it seems that never happened.

As for me, I'm not suggesting that braces are better than indentation.
In fact, requiring indentation is a good idea, and I agree that braces
can be quite ugly. It is the lack of visible block closing when there's
more than one level that I dislike.

That would probably not be so bad if, like the recent post, you used an
editor that showed faint vertical lines. In fact, that's a very good
idea, since you really need a Python-aware editor anyhow.

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


What About Next Laptop Computers?

2006-10-21 Thread Joe
L International Reveals Plans for High-Tech
Next-Generation Laptop Computer Systems

L International Computers Inc. "L" renowned manufacturer of
high-performance computers and personal/business technologies, revealed
plans for its next generation high-end laptop and ultra-portable
computer systems.

To read this articles, go to:
http://www.contactomagazine.com/laptopcomputers1006.htm

More Business and Computer News:
http://www.contactomagazine.com/business.htm

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


MySQL InterfaceError

2007-06-04 Thread Joe
I still consider myself a newbie, and being new to the list I request that
you take it easy on me.  ;)

 

We're running a RHEL LAMP server with the mod_python publisher interpreter.
The MySQLdb module seems to be giving me more problems than I had hoped for.
With a fresh restart of apache, all programs run flawlessly for an average
of 7-8 executions, but then will return an InterfaceError.  The last few
lines of the traceback are as follows:

 

File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 147, in execute

charset = db.character_set_name()

 

InterfaceError: (0, '')

 

This InterfaceError will continue sporadically about half of the time the
programs are run.  We are running mysql version 4.1.2 so I was assuming it
may be caused by the mysql_character_set_name() bug (as shown in the
comments here:
http://dev.mysql.com/doc/refman/5.0/en/mysql-character-set-name.html), but
this was ruled out when the error continued after hard coding the charset as
utf8.

 

As you can see, without any error description this is very hard to debug.  I
have spent several days researching this and have come up empty handed.  I
would appreciate any help anyone can give.  If this is the wrong list to
ask, please let me know and I will repost elsewhere.

 

Versions:

Python: 2.5.1

MySQL: 4.1.2

MySQLdb: 1.2.2

 

Thanks!

 

Jough

 

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

RE: MySQL InterfaceError

2007-06-04 Thread Joe
Sorry, forgot some valuable information.  If you couldn't tell from the
traceback, the error will be thrown during the first executed query that the
program runs into (no matter what that query is).

 

Jough

 

  _  

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Joe
Sent: Monday, June 04, 2007 4:01 PM
To: python-list@python.org
Subject: MySQL InterfaceError

 

I still consider myself a newbie, and being new to the list I request that
you take it easy on me.  ;)

 

We're running a RHEL LAMP server with the mod_python publisher interpreter.
The MySQLdb module seems to be giving me more problems than I had hoped for.
With a fresh restart of apache, all programs run flawlessly for an average
of 7-8 executions, but then will return an InterfaceError.  The last few
lines of the traceback are as follows:

 

File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 147, in execute

charset = db.character_set_name()

 

InterfaceError: (0, '')

 

This InterfaceError will continue sporadically about half of the time the
programs are run.  We are running mysql version 4.1.2 so I was assuming it
may be caused by the mysql_character_set_name() bug (as shown in the
comments here:
http://dev.mysql.com/doc/refman/5.0/en/mysql-character-set-name.html), but
this was ruled out when the error continued after hard coding the charset as
utf8.

 

As you can see, without any error description this is very hard to debug.  I
have spent several days researching this and have come up empty handed.  I
would appreciate any help anyone can give.  If this is the wrong list to
ask, please let me know and I will repost elsewhere.

 

Versions:

Python: 2.5.1

MySQL: 4.1.2

MySQLdb: 1.2.2

 

Thanks!

 

Jough

 

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

RE: MySQL InterfaceError

2007-06-06 Thread Joe
>File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 147, in execute

>charset = db.character_set_name()

> 

>InterfaceError: (0, '')

 

We got it working.  It was caused by passing a database connection to a
module:

 

import MySQLdb

import module_name

connection = MySQLdb.connect(host='localhost', user='user',
passwd='password', db='database')

module = module_name.ClassName(connection)

 

But, when the connection was made within the module itself, it would work
flawlessly every time.  Can someone explain to me why this is?  

 

Jough

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

RE: MySQL InterfaceError

2007-06-07 Thread Joe
> Try passing the cursor and not the connection -

Unfortunately this provided the same InterfaceError.  It was one of the
first options we had tried in correcting the situation.  Is there any way to
check on the status of a database connection (like an isOpen() method)?  It
appeared as though the connection (and cursor) would sporadically close upon
passing between modules.

Thanks!

Jough

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


RE: MySQL InterfaceError

2007-06-07 Thread Joe
> Huh the only thing I can find on InterfaceError is "Errors related to
> the database interface and not the database itself." You might be able
> to get some info from connection.info() . . .

Yeah, I wish there was more documentation about this type of error.  The
only thing info() tells me is that the connection is open through id ##.

> Are you using utf8? MySQLdb seems to have some problems with that.
> Also, I assume you've tried catching the error and printing the error
> message, right?

Yes, we are using utf8.  What kind of problems can be seen with it?  This is
all I have run across so far.  What type of encoding would you suggest?  I
am still new at some of this stuff, so if you could possibly explain
(off-topic, so a link is fine) the differences between database encodings I
would be grateful.

And, yes, printing the error message returns absolutely nothing.  The tuple
following InterfaceError is both the error code and message.  Unfortunately,
it will only give me (0, '') which isn't much help.

Thanks again!

Jough 

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


Case-Insensitive Sorting of Multi-Dimensional Lists

2007-06-08 Thread Joe
I have a list of lists that I would like to sort utilizing a certain index
of the nested list.  I am able to successfully use:

 

Import operator

list = [["Apple", 1], ["airplane", 2]]

list.sort(key=operator.itemgetter(0))

 

But, unfortunately, this will be case sensitive (Apple will come before
airplane because the A is capital) and I need it to be insensitive.  

 

Can someone provide some input, please?

 

Thanks in advance!

 

Jough

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

RE: Case-Insensitive Sorting of Multi-Dimensional Lists

2007-06-08 Thread Joe
> Try:
> 
> list.sort(key=lambda el: el[0].lower())

Thanks!  Worked like a charm :)

> BUT - it's not a good idea to use list as a name, 'cos list is a
> built-in, and you're obscuring it.

Oh, don't worry.  That was strictly my portrayal of the problem.

Thanks again!

Jough

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


RE: Case-Insensitive Sorting of Multi-Dimensional Lists

2007-06-08 Thread Joe
> Try:
> 
> list.sort(key=lambda el: el[0].lower())

Now, I would like to be able to specify which index to sort by.  I am not
able to pass in external variables like:

List.sort(key=lambda el: el[indexNumber].lower())

I am new to lambda and have searched for a few hours this morning, coming up
empty handed.  Is this possible?

Thanks!

Jough

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


RE: Case-Insensitive Sorting of Multi-Dimensional Lists

2007-06-08 Thread Joe
> > Now, I would like to be able to specify which index to sort by.  I am
> not
> > able to pass in external variables like:
> >
> > List.sort(key=lambda el: el[indexNumber].lower())
> 
> Why ever not?

Sorry, I should have written back with my findings.  I had run into the
problem described in this email:
http://mail.python.org/pipermail/python-list/2001-June/090863.html.  See, I
was using bare execs elsewhere in the program.

It had nothing to do with the lambda, which ended up working perfectly once
I fixed the exec.

Thanks!

Jough

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


Invitation for Python at the Southern California Linux Expo

2009-01-14 Thread joe
Greetings,

I would like to invite the Python project to attend the 7th Southern
California Linux Expo.  The show will be held February 20th-22nd, 2009 at
the Westin LAX in Los Angeles, CA.  SCALE 7x will be an excellent venue to
increase awareness and showcase the work of the Python community.

Each project will have some room in the zone on the show floor. This
will include all the usual amenities: a 6' table, chairs, a 500W power drop,
 one Ethernet drop and 3-5 complementary passes to the show.

I am including our application for dotORG exhibitors, if anyone is down in
the Southern California area, and would like to set up a booth, I
encourage you to apply. Any questions, please do not hesitate to ask.

Thanks for your time!

Joe Smith

http://scale7x.socallinuxexpo.org/conference-info/call-for-dotorg-exhibitors

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


Python at the SoCal Linux Expo

2009-02-10 Thread joe
Hey guys,

The Southern California Linux Expo, a community run conference taking
place in Los Angeles on February 20th to 22nd, is offering a 50% discount
to the Python community. When you go to register[1], just enter the promo
code: PYTHN. If you have any questions, please let me know.

Thanks!
Joe Smith
Southern California Linux Expo

[1] https://socallinuxexpo.org/reg7/



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


no module named error

2009-12-08 Thread Joe
I am trying to write/run a python script which imports from another
script which is located in my /usr/lib64/python2.6/site-packages/ dir,
but getting the following error.

$ python ./mytest.py
Traceback (most recent call last):
  File "./mytest.py", line 45, in 
  from moda import *
File "/usr/lib64/python2.6/site-packages/moda.py", line 7, in

import _moda
ImportError: No module named _moda


The script moda.py exists. My script is:

#!/usr/bin/python

import sys

from moda import *

def main(args = sys.argv[1:]):
print 'test'

if __name__ == '__main__' :
main()

Any idea what I'm doing wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no module named error

2009-12-08 Thread Joe
> But it's searching for _moda.*, most probably a binary extension. Does that
> exist, and if yes, has it the proper architecture or is it maybe 32 bit?

I'm just going by an example script. moda is a package I was given that
is written in C and has some python bindings and does run 64-bit. I'm on
gentoo. I'm not sure it's installed correctly, but it did come w/ a
setup.py, and I ran 'setup.py install' and it seemed to have installed
correctly.

$ sudo python ./setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info
Writing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info

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


Re: no module named error

2009-12-08 Thread Joe
Diez B. Roggisch wrote:
> Joe wrote:
> 
>>> But it's searching for _moda.*, most probably a binary extension. Does
>>> that exist, and if yes, has it the proper architecture or is it maybe 32
>>> bit?
>> I'm just going by an example script. moda is a package I was given that
>> is written in C and has some python bindings and does run 64-bit. I'm on
>> gentoo. I'm not sure it's installed correctly, but it did come w/ a
>> setup.py, and I ran 'setup.py install' and it seemed to have installed
>> correctly.
>>
>> $ sudo python ./setup.py install
>> running install
>> running build
>> running build_py
>> running install_lib
>> running install_egg_info
>> Removing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info
>> Writing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info
> 
> You didn't answer my question. Did it install the _moda.* file the moda.py
> is searching for? 
> 
> Diez


Yeah, that's what I meant when I said the file exists above. There's a
moda.py in /usr/lib64/python2.6/site-packages/moda.py.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no module named error

2009-12-08 Thread Joe
> 
> Please verify that it exists and has the proper architecture.
> 


Ah, ok, I thought those were one in the same. But I do have that file in
another directory elsewhere and I have that directory in my
LD_LIBRARY_PATH var.

Shouldn't that be enough to do it?



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


Re: no module named error

2009-12-08 Thread Joe
Just to clarify, I have "_moda.la" sitting in another directory which is
included in my LD_LIBRARY_PATH. And it is built for the 64bit arch.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no module named error

2009-12-10 Thread Joe
> No, the import-mechanism of python doesn't take LD_LIBRARY_PATH into
> account, and even if it did - _moda.la is a simple archive-file, not a
> shared library. It can't be dynamically loaded. Something in your
> build-process is not working.

So how should my stuff find these libs?

Here's what I've recently learned ...

So if I have the dir path of my c libs inside my exported
LD_LIBRARY_PATH (which includes the following files),  along w/ the dir
to the *.la file ...

_moda.a
_moda.la -> ../_moda.la
_moda.lai
_moda.so -> _moda.so.2.0.1
_moda.so.2 -> _moda.so.2.0.1
_moda.so.2.0.1
_moda.so.2.0.1T
_moda_la-moda_wrap.o

I get the 'ImportError: No module named _moda' error as in previous
post. But as I think your saying above, this should not work because
LD_LIBRARY_PATH doesn't get used.

I was at the python command line '>>>' and I did the following command.

import sys
sys.path.append('/home/me/my/c/libs/path/.libs')
# this is the path to the above listed files, and then when I did ...

   import moda

Everything worked just fine.

But I'm not quite sure how to fix it in my script or env.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no module named error

2009-12-10 Thread Joe

> Your installation process is botched (no idea why, you don't show us
> setup.py or anything else I asked for).

Sorry, but I do know how it's currently installed is exactly the way I
need it to be installed.

> 
> 
> All that is missing is what I've asked you now several times before:
> _moda.so is *NOT* alongside moda.py inside your python's site-packages
> directory. Copy it in there, and the import will work *without* any
> sys.path-hackery.

Yeah, that's something I don't want to do. But you've given me enough
info to help me understand what's going on and how to fix it. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 3.1.1 bytes decode with replace bug

2009-10-24 Thread Joe
The Python 3.1.1 documentation has the following example:

>>> b'\x80abc'.decode("utf-8", "strict")
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0:
unexpected code byte
>>> b'\x80abc'.decode("utf-8", "replace")
'\ufffdabc'
>>> b'\x80abc'.decode("utf-8", "ignore")
'abc'

Strict and Ignore appear to work as per the documentation but replace
does not.  Instead of replacing the values it fails:

>>> b'\x80abc'.decode('utf-8', 'replace')
Traceback (most recent call last):
  File "", line 1, in 
  File "p:\SW64\Python.3.1.1\lib\encodings\cp437.py", line 19, in
encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in
position
1: character maps to 

If this a known bug with 3.1.1?


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


Re: Python 3.1.1 bytes decode with replace bug

2009-10-24 Thread Joe

Thanks for your response.

> Please provide more information
>
> > The Python 3.1.1 documentation has the following example:
>
> Where? I could not find them

http://docs.python.org/3.1/howto/unicode.html#unicode-howto

Scroll down the page about half way to the "The String Type" section.

The example was copied from the second example with the light green
background.

> Which interpreter and system? With Python 3.1 (r31:73574, Jun 26 2009,

Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on win32

Windows 7 x64 RTM, Python 3.1.1

> Do you do a search in the issues list at bugs.python.org?

Yes, I did not see anything that seemed to apply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.1.1 bytes decode with replace bug

2009-10-24 Thread Joe
> For the reason BK explained, the important difference is that I ran in
> the IDLE shell, which handles screen printing of unicode better ;-)

Something still does not seem right here to me.

In the example above the bytes were decoded to 'UTF-8' with the
replace option so any characters that were not UTF-8 were replaced and
the resulting string is '\ufffdabc' as BK explained.  I understand
that the replace worked.

Now consider this:

Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '\ufffdabc'
>>> print(s)
Traceback (most recent call last):
  File "", line 1, in 
  File "p:\SW64\Python.3.1.1\lib\encodings\cp437.py", line 19, in
encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in
position
0: character maps to 
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

This too fails for the exact same reason (and doesn't invole decode).

In the original example I decoded to UTF-8 and in this example the
default encoding is UTF-8 so why is cp437 being used?

Thanks in advance for your assistance!






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


Re: Python 3.1.1 bytes decode with replace bug

2009-10-26 Thread Joe

Thanks Benjamin for solving the mystery of where the cp437 usage was
coming from.

So b'\x80abc'.decode("utf-8", "replace") was working properly but then
when the interactive prompt tried to print it, it was basically taking
the results and doing a
encode('cp437', 'strict') which failed because of the characters that
are not part of cp437.

It might not be a bad idea to put a note on that documentation page
because I sure others will work though the samples like I did and if
they are on Windows run into the same issue.









> Try checking sys.stdout.encoding. Then run the command chcp (not in
> the python interpreter). You'll probably get 437 from both of those.
> Just because the system encoding is set to utf-8 doesn't mean the
> console is. Nobody really uses cp437 anymore- it was replaced years
> ago by cp1252- but Microsoft is scared to do anything to cmd.exe
> because it might break somebody's 20-year-old DOS script
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.1.1 bytes decode with replace bug

2009-10-26 Thread Joe

Thanks Mark, that is a great suggestion!

> You can also replace the Unicode replacement character U+FFFD with a valid
> cp437 character before displaying it:
>
> >>> b'\x80abc'.decode('utf8','replace').replace('\ufffd','?')
>
> '?abc'
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Differences of "!=" operator behavior in python3 and python2 [ bug? ]

2013-05-12 Thread Mr. Joe
I seem to stumble upon a situation where "!=" operator misbehaves in
python2.x. Not sure if it's my misunderstanding or a bug in python
implementation. Here's a demo code to reproduce the behavior -
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function

class DemoClass(object):
def __init__(self, val):
self.val = val

def __eq__(self, other):
return self.val == other.val

x = DemoClass('a')
y = DemoClass('a')

print("x == y: {0}".format(x == y))
print("x != y: {0}".format(x != y))
print("not x == y: {0}".format(not x == y))
"""

In python3, the output is as expected:
"""
x == y: True
x != y: False
not x == y: False
"""

In python2.7.3, the output is:
"""
x == y: True
x != y: True
not x == y: False
"""
Which is not correct!!

Thanks in advance for clarifications.
Regards,
TB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-14 Thread Mr. Joe
Sorry for digging this old topic back. I see that my "'property' does not
play well with polymorphic code" comment generated some controversy. So
here's something in my defense:

Here's the link to stackoveflow topic I am talking about:

http://stackoverflow.com/questions/237432/python-properties-and-inheritance

The solution that fits my taste:
http://stackoverflow.com/a/14349742

A related blogpost:

http://requires-thinking.blogspot.com/2006/03/note-to-self-python-properties-are-non.html

Yes, I like decorators and descriptors. I also like the ability to create a
"virtual property" in a python class by binding a bunch of methods as
setter/getter. But I find the implementation of this "virtual property
feature" a bit awkward sometimes - every time I need to override a
getter/setter in a child class, I need to decorate them again. Some of you
may like this "explicitness", but I don't.

To Steven D'Aprano: Seriously, what's all the bashing in your last reply
about? You dissected my "thank-you reply" more strictly than the python
interpreter checking for syntax errors. Not in a mood for fight, but I find
your opinions about "bug finding time", "hacks" and "stackoverflow" quite
silly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

2013-05-15 Thread Mr. Joe
On Wed, May 15, 2013 at 12:15 PM, dieter  wrote:
>
>   If Python would automatically redecorate overridden methods in a derived
>   class, I would have no control over the process. What if I need
>   the undecorated method or a differently decorated method (an
>   uncached or differently cached method, in my case)?
>

On a second thought, I am convinced by your argument.

> Your getter/setter use case can quite easily be solved
> with a class "DelayedMethodAccessor":
>
>   class DelayedMethodAccess(object):
> """
> def __init__(self, name): self.__name = name
> def __call__(self, inst, *args, **kw):
>   return getattr(inst, self.__name)(*args, **kw)
>
> You can then use:
>
>prop = property(DelayedMethodAccess(""), ...)
>
> Or define a new decorator "property_by_name" and then
> use
>
>prop = property_by_name("", ...)
>
> Of course, this requires that the property name and the getter/setter
names
> differ, but this should be naturally enough.
>
>
> Python's current behavior is very natural once you know that
> decorators are just syntactic sugar and
>
>@
>def ...
>
> simply means:
>
>def ...
>f = (f)
>
> True, this is no perfect fit for all use cases - but
> such a fit (if it existed at all) would have to be so complex
> that only experts could understand it.

Thanks for these really nice patterns. They fits my problem very well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Compiler Error for build Python -3.3.0 (Suggestions)

2012-10-22 Thread Joe Davis

   The version of Python I have on my old Solaris boxes is old and
isn't supported and dosn't have all the modules that I need.I have
downloaded the new 3.3 version and have been trying to compile it and
have no luck:

After running the ./configure command I run "make" and it gives me the
following error.Does anyone know what is wrong here or what to do
about this?

Is there a location I can download a binary package of this?
Sunfreeware looks to be out of business.

Thanks

gcc -c -fno-strict-aliasing -DNDEBUG -g  -O3 -Wall -Wstrict-
prototypes-I. -I./Include-DPy_BUILD_CORE -o Python/pythonrun.o
Python/pythonrun.c
Python/pythonrun.c: In function `PyOS_getsig':
Python/pythonrun.c:2545: storage size of `context' isn't known
Python/pythonrun.c:2546: warning: implicit declaration of function
`sigaction'
Python/pythonrun.c:2547: `SIG_ERR' undeclared (first use in this
function)
Python/pythonrun.c:2547: (Each undeclared identifier is reported only
once
Python/pythonrun.c:2547: for each function it appears in.)
Python/pythonrun.c:2545: warning: unused variable `context'
Python/pythonrun.c: In function `PyOS_setsig':
Python/pythonrun.c:2588: storage size of `context' isn't known
Python/pythonrun.c:2588: storage size of `ocontext' isn't known
Python/pythonrun.c:2590: warning: implicit declaration of function
`sigemptyset'
Python/pythonrun.c:2593: `SIG_ERR' undeclared (first use in this
function)
Python/pythonrun.c:2588: warning: unused variable `context'
Python/pythonrun.c:2588: warning: unused variable `ocontext'
make: *** [Python/pythonrun.o] Error 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-18 Thread random joe
On Feb 18, 12:34 pm, Rick Johnson 
wrote:

> Louie-the-loose-screw Said: "I'll give you $15 if you'll give me $15!"

$15 dolla too beau coup! 5 dolla each!

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


Re: import os or import os.path

2011-09-06 Thread Joe Riopel
On Tue, Sep 6, 2011 at 5:25 PM, Jabba Laci  wrote:
> Hi,
>
> If I want to use the 'os.path' module, it's enought to import 'os':
>
> import os
> if os.path.isfile('/usr/bin/bash'):
>    print 'got it'
>
> In other source codes I noticed that people write 'import os.path' in
> this case. Which is better practice?

I just followed what the help said:

""
DESCRIPTION
Instead of importing this module directly, import os and refer to
this module as os.path.
""
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating Command Line Options

2011-03-23 Thread Joe Riopel
On Wed, Mar 23, 2011 at 10:10 AM, T  wrote:
> For a Python script with multiple command line options, what is the
> best way to go about validating that only certain options are used
> together?  For example, say -s, -t, and -v are all valid options, but
> should never be used together (i.e. -s -t would be invalid).  Thanks
> in advance.

It looks like argparse supports mutually exclusive option groups.
http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#add_mutually_exclusive_group
-- 
http://mail.python.org/mailman/listinfo/python-list


FBI wants public help solving encrypted notes from murder mystery

2011-03-30 Thread Joe Snodgrass

FBI cryptanalysis hasn’t decrypted notes from 1999 murder mystery

http://tinyurl.com/4d56zsz

The FBI is seeking the public's help in breaking the encrypted code
found in two notes discovered on the body of a murdered man in 1999.

The FBI says that officers in St. Louis, Missouri discovered the body
of 41-year-old Ricky McCormick on June 30, 1999 in a field and the
clues regarding the homicide were two encrypted notes found in the
victim's pants pockets.

The FBI says that despite extensive work by its Cryptanalysis and
Racketeering Records Unit (CRRU), and the American Cryptogram
Association, the meanings of those two coded notes remain a mystery
and McCormick's murderer has never been found. One has to wonder
though, if the FBI can't figure this out, who can? But I digress.

>From the FBI: "The more than 30 lines of coded material use a
maddening variety of letters, numbers, dashes, and parentheses.
McCormick was a high school dropout, but he was able to read and write
and was said to be 'street smart.' According to members of his family,
McCormick had used such encrypted notes since he was a boy, but
apparently no one in his family knows how to decipher the codes, and
it's unknown whether anyone besides McCormick could translate his
secret language. Investigators believe the notes in McCormick's
pockets were written up to three days before his death."

"Standard routes of cryptanalysis seem to have hit brick walls," said
CRRU chief Dan Olson in a statement. To move the case forward,
examiners need another sample of McCormick's coded system-or a similar
one-that might offer context to the mystery notes or allow valuable
comparisons to be made. Or, short of new evidence, Olson said, "Maybe
someone with a fresh set of eyes might come up with a brilliant new
idea."

The FBI says it has always relied on public tips and other assistance
to solve crimes though breaking a code may represent a special
circumstance.

For larger images of the notes go here. [LINK]

If you have an idea how to break the code, have seen similar codes, or
have any information about the Ricky McCormick case, write to CRRU at
the following address:

FBI Laboratory
Cryptanalysis and Racketeering Records Unit
2501 Investigation Parkway
Quantico, VA 22135
Attn: Ricky McCormick Case

There is no reward being offered, just the knowledge that you may be
solving an intriguing murder mystery, the FBI stated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FBI wants public help solving encrypted notes from murder mystery

2011-03-31 Thread Joe Snodgrass
On Mar 30, 10:18 pm, "Stretto"  wrote:
> "Joe Snodgrass"  wrote in message
>
> news:c37e8e0b-a825-4ac5-9886-8828ab1fa...@x8g2000prh.googlegroups.com...
>
>
>
>
>
> > FBI cryptanalysis hasn’t decrypted notes from 1999 murder mystery
>
> >http://tinyurl.com/4d56zsz
>
> > The FBI is seeking the public's help in breaking the encrypted code
> > found in two notes discovered on the body of a murdered man in 1999.
>
> > The FBI says that officers in St. Louis, Missouri discovered the body
> > of 41-year-old Ricky McCormick on June 30, 1999 in a field and the
> > clues regarding the homicide were two encrypted notes found in the
> > victim's pants pockets.
>
> > The FBI says that despite extensive work by its Cryptanalysis and
> > Racketeering Records Unit (CRRU), and the American Cryptogram
> > Association, the meanings of those two coded notes remain a mystery
> > and McCormick's murderer has never been found. One has to wonder
> > though, if the FBI can't figure this out, who can? But I digress.
>
> > From the FBI: "The more than 30 lines of coded material use a
> > maddening variety of letters, numbers, dashes, and parentheses.
> > McCormick was a high school dropout, but he was able to read and write
> > and was said to be 'street smart.' According to members of his family,
> > McCormick had used such encrypted notes since he was a boy, but
> > apparently no one in his family knows how to decipher the codes, and
> > it's unknown whether anyone besides McCormick could translate his
> > secret language. Investigators believe the notes in McCormick's
> > pockets were written up to three days before his death."
>
> > "Standard routes of cryptanalysis seem to have hit brick walls," said
> > CRRU chief Dan Olson in a statement. To move the case forward,
> > examiners need another sample of McCormick's coded system-or a similar
> > one-that might offer context to the mystery notes or allow valuable
> > comparisons to be made. Or, short of new evidence, Olson said, "Maybe
> > someone with a fresh set of eyes might come up with a brilliant new
> > idea."
>
> > The FBI says it has always relied on public tips and other assistance
> > to solve crimes though breaking a code may represent a special
> > circumstance.
>
> > For larger images of the notes go here. [LINK]
>
> > If you have an idea how to break the code, have seen similar codes, or
> > have any information about the Ricky McCormick case, write to CRRU at
> > the following address:
>
> > FBI Laboratory
> > Cryptanalysis and Racketeering Records Unit
> > 2501 Investigation Parkway
> > Quantico, VA 22135
> > Attn: Ricky McCormick Case
>
> > There is no reward being offered, just the knowledge that you may be
> > solving an intriguing murder mystery, the FBI stated.
>
> No other information about the guy? It might help. If the note is of any use
> then people and places would be in it. If that is the case then it would
> help to know where he lived and some of the names of people he knows.
>
> The note seems like it may not be just encrypted but a sort of
> compression(or rather shorthand/jargon) was used. Was the guy a drug dealer?
> It could be a list of "clients" or information about where he sold drugs(the
> numbers look like street addresses or amounts.
>
> If these kinda notes were so common from this guy then surely the FBI should
> have many more?
>
> Seems like the FBI could do more if they wanted it really solved...

As to which crime was being committed, I'm going with numbers running
or loan sharking.  There's no reason for any crook to keep any record
of any other crime, except prostitution, where phone books come in
handy.

Thievery is not an honest business, and records of what went down,
where and with whom can only hurt you.  Unless of course, it's a grand
list of felonies that he was using to blackmail the participants.

But I can't see gathering that much info from blackmail.  I always
thought it involved one guy blackmailing one victim.  This would imply
a factory scale process, and he'd need some way to lure his prey into
the trap.

Of course, that WOULD be a good way to get murdered.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FBI wants public help solving encrypted notes from murder mystery

2011-04-02 Thread Joe Snodgrass
On Apr 1, 10:54 am, David Bernier  wrote:
> haha doh wrote:
> > On Mar 31, 3:15 pm, Joe Snodgrass  wrote:
>
> [...]
>
>
>
> >> As to which crime was being committed, I'm going with numbers running
> >> or loan sharking.  There's no reason for any crook to keep any record
> >> of any other crime, except prostitution, where phone books come in
> >> handy.
>
> >> Thievery is not an honest business, and records of what went down,
> >> where and with whom can only hurt you.  Unless of course, it's a grand
> >> list of felonies that he was using to blackmail the participants.
>
> >> But I can't see gathering that much info from blackmail.  I always
> >> thought it involved one guy blackmailing one victim.  This would imply
> >> a factory scale process, and he'd need some way to lure his prey into
> >> the trap.
>
> >> Of course, that WOULD be a good way to get murdered.
> > This is him
> >http://img851.imageshack.us/i/4d93ac54b10bcimage.jpg/
>
> True indeed! , according to a story posted on March 30 on the
> website of the St. Louis Post-Dispatch:
> <http://www.stltoday.com/news/local/metro/ad567e00-5b13-11e0-8ed4-0012...>
> .
>
> That web page has a link to a 1999 article on the discovery of the body:
> <http://www.stltoday.com/news/article_bcc02074-5b1a-11e0-b199-0017a4a7...> .
>
> An officer with the local Major Case Squad unit is quoted there. I quote
> from the 1999 story:
>
> << "We cannot find any motive for his death, " he said.
> "We're not absolutely sure that this is a homicide." >> .

What's the cause of death?
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   >