What is the semantics meaning of 'object'?

2013-06-22 Thread Adam
class FooBar(object):
def __init__(self):
...

Inheritance usually takes a class name to indicate which class is the 'parent' 
class. However, in the previous example, from a django book, the class actually 
takes an 'object' like parameter, doesn't it? What is the semantics meaning of 
such kind of notation?

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


PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-26 Thread Adam
Host OS:Ubuntu 10.04 LTS
Guest OS:Windows XP Pro SP3


I am able to open port COM4 with Terminal emulator.

So, what can cause PySerial to generate the following error ...

C:\Wattcher>python wattcher.py
Traceback (most recent call last):
  File "wattcher.py", line 56, in 
ser.open()
  File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in 
open
raise SerialException("could not open port %s: %s" % (self.portstr, 
ctypes.WinError()))
serial.serialutil.SerialException: could not open port COM4: [Error 5] 
Access is denied.


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


Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"John Nagle"  wrote in message 
news:jse604$1cq$1...@dont-email.me...
> On 6/26/2012 9:12 PM, Adam wrote:
>> Host OS:Ubuntu 10.04 LTS
>> Guest OS:Windows XP Pro SP3
>>
>>
>> I am able to open port COM4 with Terminal emulator.
>>
>> So, what can cause PySerial to generate the following error ...
>>
>> C:\Wattcher>python wattcher.py
>> Traceback (most recent call last):
>>File "wattcher.py", line 56, in 
>>  ser.open()
>>File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, 
>> in
>> open
>>  raise SerialException("could not open port %s: %s" % (self.portstr,
>> ctypes.WinError()))
>> serial.serialutil.SerialException: could not open port COM4: [Error 5]
>> Access is denied.
>
> Are you trying to access serial ports from a virtual machine?
> Which virtual machine environment?  Xen?  VMware? QEmu?  VirtualBox?
> I wouldn't expect that to work in most of those.
>
> What is "COM4", anyway?   Few machines today actually have four
> serial ports.  Is some device emulating a serial port?
>
> John Nagle
>

Thanks, and yes, I am using VirtualBox.  My laptop does not have a serial 
port so
I use a USB-to-serial converter, which is assigned COM4.


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


Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"Paul"  wrote in message 
news:jseu9c$sp3$1...@dont-email.me...
> Adam wrote:
>> "John Nagle"  wrote in message 
>> news:jse604$1cq$1...@dont-email.me...
>>> On 6/26/2012 9:12 PM, Adam wrote:
>>>> Host OS:Ubuntu 10.04 LTS
>>>> Guest OS:Windows XP Pro SP3
>>>>
>>>>
>>>> I am able to open port COM4 with Terminal emulator.
>>>>
>>>> So, what can cause PySerial to generate the following error ...
>>>>
>>>> C:\Wattcher>python wattcher.py
>>>> Traceback (most recent call last):
>>>>File "wattcher.py", line 56, in 
>>>>  ser.open()
>>>>File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, 
>>>> in
>>>> open
>>>>  raise SerialException("could not open port %s: %s" % 
>>>> (self.portstr,
>>>> ctypes.WinError()))
>>>> serial.serialutil.SerialException: could not open port COM4: [Error 5]
>>>> Access is denied.
>>> Are you trying to access serial ports from a virtual machine?
>>> Which virtual machine environment?  Xen?  VMware? QEmu?  VirtualBox?
>>> I wouldn't expect that to work in most of those.
>>>
>>> What is "COM4", anyway?   Few machines today actually have four
>>> serial ports.  Is some device emulating a serial port?
>>>
>>> John Nagle
>>>
>>
>> Thanks, and yes, I am using VirtualBox.  My laptop does not have a serial 
>> port so
>> I use a USB-to-serial converter, which is assigned COM4.
>>
>
> Doesn't VirtualBox allow "remapping" serial ports ? I thought you
> could have COM 4 in the host OS, and make it COM 1 or COM 2 in
> the guest. Something like that.
>
> http://virtuatopia.com/images/6/60/Virtualbox_serial_port_settings.jpg
>
> Also, Windows (as a host), is notorious for stealing control of
> COM ports. Even Windows software, when you run it, would report
> "COM 4 is busy". Then, you have to track down *why* it's busy.
> Is it that FAX software you installed ? The GPS software
> that talks to your GPS serial interface ?
>
> In theory, the "Handle" program is supposed to identify what
> is keeping a COM port busy, but I don't get the desired
> results from it very often. You need to know the naming
> convention for virtual COM ports (COM4 via USB to serial, is
> more virtual than physical). That's what makes it harder
> to track down.
>
> These are some names for COM ports, in Windows. The last two entries,
> are my USB to serial adapters. VCP1 functions as COM3.
> VCP0 functions as COM4. The VCP part is what would be
> listed in "Handle" from Sysinternals. The \device\serial
> format, is more likely to be used with true "native"
> motherboard serial ports.
>
>\device\serial
>
>ups.exe pid: 1072 NT AUTHORITY\SYSTEM
>   98: File  (---)   \Device\VCP0
>hypertrm.exe pid: 3404 ComputerName\UserID (claims to use COM3)
>   E0: File  (---)   \Device\VCP1
>
> You can download "Handle" and play with it here.
>
> http://technet.microsoft.com/en-us/sysinternals/bb896655
>
> Note that, in my Handle results, at the time I was running
> the Windows provided ups.exe to talk to my external UPS
> (uninterruptible power supply). So that's what that
> reference is. The "hypertrm" one, is me using the
> built-in Windows terminal software, to talk to COM3,
> to keep the port artificially busy for the purposes
> of testing.
>
> If things were working well in your case, you *might*
> see something of this form. If not, you'd instead
> see the name of the process that has "stolen" the
> com port.
>
>virtualbox.exe pid: 1234 ComputerName\UserID
>   E0: File  (---)  \Device\VCP0
>
> HTH,
>Paul


Thanks (Guru Paul), I've been using the USB-to-serial converter successfully 
without
enabling/remapping via VBox Settings=>Serial Ports (which are both "not" 
enabled).
I can see the serial port COM4 under Device Manager though.  So, maybe 
enabling is
necessary when the host has "native" serial ports, which my laptop does not 
have.

>From the output generated by Handle.exe, here's the section for TeraTerm ...
--
ttermpro.exe pid: 596 VBOX_WINXPPRO\adam(claims to use COM4)
C: File  (RW-)   D:\downloads\Tera Term Pro\ttpro313
   2C: Section   \BaseNamedObjects\ttset_memfilemap
   44: File  (RW-) 

Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"Paul"  wrote in message 
news:jsfatv$djt$1...@dont-email.me...
> Adam wrote:
>> "Paul"  wrote in message 
>> news:jseu9c$sp3$1...@dont-email.me...
>>> Adam wrote:
>>>> "John Nagle"  wrote in message 
>>>> news:jse604$1cq$1...@dont-email.me...
>>>>> On 6/26/2012 9:12 PM, Adam wrote:
>>>>>> Host OS:Ubuntu 10.04 LTS
>>>>>> Guest OS:Windows XP Pro SP3
>>>>>>
>>>>>>
>>>>>> I am able to open port COM4 with Terminal emulator.
>>>>>>
>>>>>> So, what can cause PySerial to generate the following error ...
>>>>>>
>>>>>> C:\Wattcher>python wattcher.py
>>>>>> Traceback (most recent call last):
>>>>>>File "wattcher.py", line 56, in 
>>>>>>  ser.open()
>>>>>>File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 
>>>>>> 56, in
>>>>>> open
>>>>>>  raise SerialException("could not open port %s: %s" % 
>>>>>> (self.portstr,
>>>>>> ctypes.WinError()))
>>>>>> serial.serialutil.SerialException: could not open port COM4: [Error 
>>>>>> 5]
>>>>>> Access is denied.
>>>>> Are you trying to access serial ports from a virtual machine?
>>>>> Which virtual machine environment?  Xen?  VMware? QEmu?  VirtualBox?
>>>>> I wouldn't expect that to work in most of those.
>>>>>
>>>>> What is "COM4", anyway?   Few machines today actually have four
>>>>> serial ports.  Is some device emulating a serial port?
>>>>>
>>>>> John Nagle
>>>>>
>>>> Thanks, and yes, I am using VirtualBox.  My laptop does not have a 
>>>> serial port so
>>>> I use a USB-to-serial converter, which is assigned COM4.
>>>>
>>> Doesn't VirtualBox allow "remapping" serial ports ? I thought you
>>> could have COM 4 in the host OS, and make it COM 1 or COM 2 in
>>> the guest. Something like that.
>>>
>>> http://virtuatopia.com/images/6/60/Virtualbox_serial_port_settings.jpg
>>>
>>> Also, Windows (as a host), is notorious for stealing control of
>>> COM ports. Even Windows software, when you run it, would report
>>> "COM 4 is busy". Then, you have to track down *why* it's busy.
>>> Is it that FAX software you installed ? The GPS software
>>> that talks to your GPS serial interface ?
>>>
>>> In theory, the "Handle" program is supposed to identify what
>>> is keeping a COM port busy, but I don't get the desired
>>> results from it very often. You need to know the naming
>>> convention for virtual COM ports (COM4 via USB to serial, is
>>> more virtual than physical). That's what makes it harder
>>> to track down.
>>>
>>> These are some names for COM ports, in Windows. The last two entries,
>>> are my USB to serial adapters. VCP1 functions as COM3.
>>> VCP0 functions as COM4. The VCP part is what would be
>>> listed in "Handle" from Sysinternals. The \device\serial
>>> format, is more likely to be used with true "native"
>>> motherboard serial ports.
>>>
>>>\device\serial
>>>
>>>ups.exe pid: 1072 NT AUTHORITY\SYSTEM
>>>   98: File  (---)   \Device\VCP0
>>>hypertrm.exe pid: 3404 ComputerName\UserID (claims to use COM3)
>>>   E0: File  (---)   \Device\VCP1
>>>
>>> You can download "Handle" and play with it here.
>>>
>>> http://technet.microsoft.com/en-us/sysinternals/bb896655
>>>
>>> Note that, in my Handle results, at the time I was running
>>> the Windows provided ups.exe to talk to my external UPS
>>> (uninterruptible power supply). So that's what that
>>> reference is. The "hypertrm" one, is me using the
>>> built-in Windows terminal software, to talk to COM3,
>>> to keep the port artificially busy for the purposes
>>> of testing.
>>>
>>> If things were working well in your case, you *might*
>>> see something of this form. If not, you'd instead
>>> see the name of the process that has "stolen" the
>>> com port.
>>>
>>>virtualbox.exe pid: 1234 ComputerName

Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"Paul"  wrote in message 
news:jsfhv2$ta9$1...@dont-email.me...
> Adam wrote:
>
>>
>> This is a tough one.
>
> Try
>
>handle -a > allhand.txt
>
> Then open the allhand.txt with Notepad and look for interesting entries.
>
> ***
>
> I tested right now, and first opened a session in HyperTerminal with one
> of my USB to serial adapters. The second serial adapter, is connect to a
> UPS, looking for a shutdown message. So the second entry should be present
> at all times.
>
> hypertrm.exe pid: 3452
> ...
>   120: File  (---)   \Device\VCP1
>
>
> ups.exe pid: 1568 NT AUTHORITY\SYSTEM
> ...
>98: File  (---)   \Device\VCP0
>
> I don't have any "serial" entries on this machine. But one of
> my other machines, has a real COM port on the SuperI/O chip,
> so the entries for that would involve the word "serial" in some
> way. The USB ones, at least the ones I've got, say VCP. Possibly
> because one of the driver files sets up virtual COM ports. There
> is a control panel for the driver, that maps a virtual COM port,
> to a COM port number, like COM3 and COM4 in this case.
>
>   Paul


Thanks (Guru Paul), you're the best.  I think we may have something this 
time ...

  144: File  (---)   \Device\ProlificSerial3

And, TeraTerm (using COM4) is open and receiving data wirelessly.

>From the output generated by "handle -a", here's the section for TeraTerm 
...
--
ttermpro.exe pid: 3648 VBOX_WINXPPRO\adam(claims to use COM4)
4: KeyedEvent\KernelObjects\CritSecOutOfMemoryEvent
8: Directory \KnownDlls
C: File  (RW-)   D:\downloads\Tera Term Pro\ttpro313
   10: Event
   14: Directory \Windows
   18: Port
   1C: WindowStation \Windows\WindowStations\WinSta0
   20: Desktop   \Default
   24: WindowStation \Windows\WindowStations\WinSta0
   28: Directory \BaseNamedObjects
   2C: Section   \BaseNamedObjects\ttset_memfilemap
   30: Semaphore
   34: Semaphore
   38: Key   HKLM
   3C: Event
   40: Semaphore 
\BaseNamedObjects\shell.{A48F1A32-A340-11D1-BC6B-00A0C90312E1}
   44: File  (RW-) 
C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202
   48: File  (---)   \Device\KsecDD
   4C: Key   HKCU
   50: Key   HKCU\CLSID
   54: File  (RW-) 
C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86
   58: Mutant
   5C: Event \BaseNamedObjects\crypt32LogoffEvent
   60: Event
   64: Mutant
   68: Event
   6C: Event
   70: Section 
\BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004
   74: Event
   78: File  (RWD)   C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl
   7C: Semaphore
   80: Semaphore
   84: Semaphore
   88: Semaphore
   8C: Semaphore
   90: Semaphore
   94: Semaphore
   98: Semaphore
   9C: Semaphore
   A0: Semaphore
   A4: Semaphore
   A8: Semaphore
   AC: Section 
\BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004
   B0: Port
   B4: Section
   B8: Key   HKCU
   BC: Mutant 
\BaseNamedObjects\CTF.LBES.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004
   C0: File  (---)   \Device\Tcp
   C4: File  (---)   \Device\Tcp
   C8: File  (---)   \Device\Ip
   CC: File  (---)   \Device\Ip
   D0: File  (---)   \Device\Ip
   D4: Semaphore
   D8: Semaphore
   DC: Key   HKLM\SYSTEM\ControlSet001\Services\Tcpip\Linkage
   E0: Key   HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters
   E4: Key 
HKLM\SYSTEM\ControlSet001\Services\NetBT\Parameters\Interfaces
   E8: Key   HKLM\SYSTEM\ControlSet001\Services\NetBT\Parameters
   EC: Threadttermpro.exe(3648): 3684
   F0: Event
   F4: Key 
HKLM\SYSTEM\ControlSet001\Services\WinSock2\Parameters\Protocol_Catalog9
   F8: Event
   FC: Key 
HKLM\SYSTEM\ControlSet001\Services\WinSock2\Parameters\NameSpace_Catalog5
  100: Section 
\BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004
  104: Key   HKLM\SOFTWARE\Microsoft\SystemCertificates\My
  108: File  (RW-)   D:\downloads\Tera Term Pro\ttpro313\httplog.log
  10C: Mutant 
\BaseNamedObjects\CTF.Compart.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004
  110: Mutant 
\BaseNamedObjects\CTF.Asm.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004
  114: Mutant 
\BaseNamedObjects\CTF.Layouts.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004
  118: Mutant 
\BaseNamedObjects\CTF.TMD.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004
  11C: Mutant 
\BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004MUTEX.DefaultS-1-5-21-1801674531-1078145449-195799

Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"Grant Edwards"  wrote in message 
news:jsftah$bb5$1...@reader1.panix.com...
> On 2012-06-27, Adam  wrote:
>
>> The Python script needed a call to ser.close() before ser.open() in
>> order to work.
>
> IOW, the port opened OK, but when you tried to open it a second time
> without closing it first, _that's_ when the .open() call failed.
>
> That's a restriction built in to Win32.  You can't open a serial port
> that's already open.  [Linux doesn't have that restriction.]
>
> Why do you need to open it a second time?
>
> -- 
> Grant Edwards   grant.b.edwardsYow! Send your 
> questions to
>  at   ``ASK ZIPPY'', Box 
> 40474,
>  gmail.comSan Francisco, CA 94140,
>   USA


As far as I can tell, the wireless hardware connected to the USB-to-serial 
converter is
receiving data (which may have the serial port open?).  I can see the data 
being
received in TeraTerm (using COM4).  After closing TeraTerm,
I start up the Python script and get the following error message ...

C:\Wattcher>python wattcher.py
Traceback (most recent call last):
  File "wattcher.py", line 56, in 
ser.open()
  File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in
open
raise SerialException("could not open port %s: %s" % (self.portstr,
ctypes.WinError()))
serial.serialutil.SerialException: could not open port COM4: [Error 5]
Access is denied.


Searching for similar encounters of this error message,
some people said that calling ser.close() before ser.open()
solved the problem.  And, it worked for me as well.

Is this considered a chicken & egg situation?


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


Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"Temia Eszteri"  wrote in message 
news:ra2nu7h75720i75ijhabg12dngrab75...@4ax.com...
> On Wed, 27 Jun 2012 22:18:59 + (UTC), Grant Edwards
>  wrote:
>
>>> Can you post a small example showing what you're doing?
>>
>>The best way to get help is to write as small a program as possible
>>that demonstrates the problem, and post it.  I'll help you get
>>started...
>>
>>Does this program work?
>>
>>import serial
>>ser = serial.Serial("COM4")
>>ser.close()
>>
>>At the moment, I don't have access to a Windows machine, but I think
>>the above should run without any errors.  If it works, then you've
>>successfully opened and closed the COM4 port.  Start adding
>>"features", in increments as small as possible, until the program
>>fails.
>>
>>Then try to remove stuff that's not needed while still keeping the
>>failure.
>>
>>IOW, try to find the smallest possible program that fails.
>>
>>Usually, in the process of doing that, you'll figure out what you were
>>doing wrong.  If not, post the smallest failing program you can come
>>up with, and somebody will be able to help.
>>
>>If you won't show us what you're doing, we can't tell you what you're
>>doing wrong.
>
> Actually, I believe someone in an earlier thread in the newsgroup or
> elsewhere pointed out that serial ports automatically open under
> Windows. I'd have to look it back up when I have the time, which I
> don't have at the moment, unfortunately.
>
> ~Temia
> -- 
> The amazing programming device: fuelled entirely by coffee, it codes while
> awake and tests while asleep!


Thanks, I think I read that as well but can't recall where.

I am just running Python scripts (downloaded),
which is not opening the serial port more than once (as Grant keeps 
assuming).


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


Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-27 Thread Adam

"Grant Edwards"  wrote in message 
news:jsg4o8$o4p$1...@reader1.panix.com...
> On 2012-06-27, Adam  wrote:
>>
>>> Actually, I believe someone in an earlier thread in the newsgroup or
>>> elsewhere pointed out that serial ports automatically open under
>>> Windows. I'd have to look it back up when I have the time, which I
>>> don't have at the moment, unfortunately.
>
> What they're referring to is that on startup, Windows used to open
> serial ports and query them to see if there was a serial mouse
> connected.  If it _thought_ it found a mouse, it would then hold the
> port. I don't think that behavior has been enabled by default for a
> long time.
>
> If that were the case, then your terminal program wouldn't be able to
> open the port either.
>
> However, IIRC, some versions of windows do open and then close the
> ports during the bus/device enumeration step of startup. However, they
> don't keep the port open, so it doesn't affect the ability of user
> applications to later open the port.
>
>> Thanks, I think I read that as well but can't recall where.
>>
>> I am just running Python scripts (downloaded), which is not opening
>> the serial port more than once (as Grant keeps assuming).
>
> Well, I'm assuming your description of what you're doing is accurate.
>
> If you're telling the truth, then the program is opening the port more
> than once.
>
> If the port wasn't already open, then calling ser.close() wouldn't do
> _anything_.  Here's the close() implmentation from pyserial:
>
>def close(self):
>"""Close port"""
>if self._isOpen:
>if self.hComPort:
># Restore original timeout values:
>win32.SetCommTimeouts(self.hComPort, self._orgTimeouts)
># Close COM-Port:
>win32.CloseHandle(self.hComPort)
>win32.CloseHandle(self._overlappedRead.hEvent)
>win32.CloseHandle(self._overlappedWrite.hEvent)
>self.hComPort = None
>self._isOpen = False
>
> There's only _one_ place where self._isOpen is set to True, and that's
> at the end of the open() call:
>
>def open(self):
>"""Open port with current settings. This may throw a 
> SerialException
>   if the port cannot be opened."""
> [...]
>self._overlappedWrite.hEvent = win32.CreateEvent(None, 0, 0, None)
>self._isOpen = True
>
> If you have to add the call "ser.close()" before you can open the port
> with "ser.open()", then that means that the port _was_already_open_.
>
> -- 
> Grant Edwards   grant.b.edwardsYow! World War III?
>  at   No thanks!
>  gmail.com


Obviously pySerial considers the serial port open and will not open an 
already open serial port.
However, why is it that TeraTerm can open the serial port?

Here's the link where I read about calling ser.close() before ser.open() ...

Trying to open a serial port with pyserial on WinXP -> "Access denied"
http://stackoverflow.com/questions/2063257/trying-to-open-a-serial-port-with-pyserial-on-winxp-access-denied


Here's the Python scripts ...
https://github.com/adafruit/Tweet-a-Watt/downloads
Click on the "Download as ..." button for the Python scripts


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


Re: PySerial could not open port COM4: [Error 5] Access is denied - please help

2012-06-28 Thread Adam

"Grant Edwards"  wrote in message 
news:jshotj$s55$1...@reader1.panix.com...
> On 2012-06-28, Adam  wrote:
>
>> Obviously pySerial considers the serial port open
>
> Because it's already been opened by the Python program.
>
>> and will not open an already open serial port.
>
> Pyserial will happily try if you call the open() of a port that's
> already open, but Windows will return an error.
>
>> However, why is it that TeraTerm can open the serial port?
>
> Because TeraTerm only opens it once.
>
>> Here's the link where I read about calling ser.close() before
>> ser.open() ...
>>
>> Trying to open a serial port with pyserial on WinXP -> "Access denied"
>>
>> http://stackoverflow.com/questions/2063257/trying-to-open-a-serial-port-with-pyserial-on-winxp-access-denied
>
> That code is broken.
>
> The port is opened by this line:
>
> self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, 
> bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, 
> stopbits=serial.STOPBITS_ONE, timeout=1)
>
> And then the author tries to _open_it_a_second_time_ here:
>
> self.ser.open()
>
>> Here's the Python scripts ...
>> https://github.com/adafruit/Tweet-a-Watt/downloads
>> Click on the "Download as ..." button for the Python scripts
>
> Like I kept telling you, those programs are trying to re-open a port
> that they've already open.  Here's the erroneous code:
>
> wattcher.py:
>
>53
>54  # open up the FTDI serial port to get data transmitted to xbee
>55  ser = serial.Serial(SERIALPORT, BAUDRATE)
>56  ser.open()
>57
>
> Line 55 opens the serial port.
>
> Line 56 tries to _open_it_again_.  _The_port_is_already_open_.
> Windows doesn't allow a serial port to be opened twice, therefore the
> ser.open() call raises an exception.
>
> Just delete line 56.
>
>
> The same thing happens here:
>
> gmeter-wattcher.py
>
>83
>84  # open up the FTDI serial port to get data transmitted to xbee
>85  ser = serial.Serial(SERIALPORT, BAUDRATE)
>86  ser.open()
>87
>
> Just delete line 86.
>
> See how simple it was to get the problem solved once you posted the
> actual code?
>
> -- 
> Grant Edwards   grant.b.edwardsYow! HUMAN REPLICAS are
>  at   inserted into VATS of
>  gmail.comNUTRITIONAL YEAST ...


Thanks, Grant !


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


Re: PySerial could not open port COM4: [Error 5] Access is denied- please help

2012-06-28 Thread Adam

"Roel Schroeven"  wrote in message 
news:mailman.1618.1340910525.4697.python-l...@python.org...
> Temia Eszteri schreef:
>> Actually, I believe someone in an earlier thread in the newsgroup or
>> elsewhere pointed out that serial ports automatically open under
>> Windows. I'd have to look it back up when I have the time, which I
>> don't have at the moment, unfortunately.
>
> That doesn't have anything to do with Windows, but with how pySerial 
> works. See the documentation for __init__():
>
> "The port is immediately opened on object creation, when a port is given. 
> It is not opened when port is None and a successive call to open() will be 
> needed."
>
> So if your script does something like
>
> prt = serial.Serial('COM4')
>
> then pySerial automatically opens the port, and you shouldn't call 
> prt.open() anymore.
>
> If, on the contrary, you do something like
>
> prt = serial.Serial()
> prt.port = 'COM4'
>
> then pySerial doesn't open the port, and you have to call prt.open() to do 
> it.
>
> PySerial has this same behavior on both Windows and Linux. The difference 
> might be that on Linux it is possible to open serial ports more than once, 
> while that doesn't work on Windows.
>
> Best regards,
> Roel
>


Thanks for the info.  Your explanation helps a lot.



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


Re: crash while using PyCharm / Python3

2016-05-03 Thread Adam

"Jonathan N. Little"  wrote in message 
news:ncqc7j$na1$1...@dont-email.me...
> Adam wrote:
>> "Adam"  wrote in message
>> news:ncprqb$tl9$1...@news.albasani.net...
>>>
>>> "Jonathan N. Little"  wrote in message
>>> news:ncpjj0$7ug$1...@dont-email.me...
>>>> Adam wrote:
>>>>> There ought to be a way to just reinstall the graphics subsystem 
>>>>> rather
>>>>> than
>>>>> an all-or-none installation approach.
>>>>
>>>> Yes you can. Did it for a borked install of the nVidia driver. 
>>>> reference
>>>> this:
>>>>
>>>> <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx>
>>>
>>> Thanks, even after doing the following...
>>>
>>> Problem: Need to purge -fglrx
>>>
>>> Typically, the following manual commands will properly uninstall -fglrx:
>>>
>>>   $ sudo apt-get remove --purge xorg-driver-fglrx fglrx*
>>>   $ sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri
>>> xserver-xorg-core
>>>   $ sudo dpkg-reconfigure xserver-xorg
>>>
>>> I still get that dreaded "The system is running in low-graphics mode"
>>> error.
>>> And, recovery mode failsafeX and Ctrl+Alt+F1 hangs with the following...
>>>
>>> 
>>> Initializing built-in extension MIT-SCREEN-SAVER
>>> Initializing built-in extension DOUBLE-BUFFER
>>> Initializing built-in extension RECORD
>>> Initializing built-in extension DPMS
>>> Initializing built-in extension Present
>>> Initializing built-in extension DRI3
>>> Initializing built-in extension X-Resource
>>> Initializing built-in extension XVideo
>>> Initializing built-in extension XVideo-MotionCompensation
>>> Initializing built-in extension SELinux
>>> Initializing built-in extension XFree86-VidModeExtension
>>> Initializing built-in extension XFree86-DGA
>>> Initializing built-in extension XFree86-DRI
>>> Initializing built-in extension DRI2
>>> Loading extension GLX
>>> 
>>>
>>
>> After trying the following...
>>
>> http://askubuntu.com/questions/577093/how-to-install-gnome-desktop
>>
>> $ sudo apt-get update
>> $ sudo apt-get install gnome-shell
>>
>>
>> http://tipsonubuntu.com/2014/06/06/change-display-manager-ubuntu-14-04/
>>
>> $ sudo dpkg-reconfigure lightdm
>
> Not sure about ATI, but when you purge the nVidia driver it takes Unity 
> with it so I had to reinstall unity-desktop afterwards. If you want 
> lightdm but are now using gdm, maybe it happened because unity-desktop was 
> uninstalled and you just installed gnome-shell, your can reset:
>
> sudo dpkg-reconfigure gdm
>
> and select lightdm from the list.
>

Today, I tried to switch from gdm back to lightdm and
still encountered the "The system is running in low-graphics mode" problem 
until I found...

NumLock Key ON...
http://ubuntuforums.org/showthread.php?t=2218111

grumblebum2 provided the fix in post #9...

For NumLock key ON (in Ubuntu 14.04), add...

greeter-setup-script=/usr/bin/numlockx on

to/usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf
(not/etc/lightdm/lightdm.conf, which I deleted since there were no other 
settings)


>
> -- 
> Take care,
>
> Jonathan
> ---
> LITTLE WORKS STUDIO
> http://www.LittleWorksStudio.com 


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


Re: FTP over TLS

2005-11-28 Thread adam
I'm not 100% sure whether this answers your problem, but I would ignore
getting a special TLS module and just concentrate on the ftp side of
the protocol. If your connection to your ftp server must be in TLS, you
could modify you socket module similar to how I have using this diff
(against 2.3.4) as inspiration.

http://www.ninjatactics.com/python/ssl-patch.txt

This way, you only need to worry about one thing, not two. I suspect
then your program flow would become
1) FTP client contacts server, sends command requesting secure
connection.
2) Server responds by sending some sort of request for SSL
3) SSL your socket to the FTP server
4) Continue on your merry FTP way.

-adam

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


getting words from readline

2005-09-10 Thread Adam

How is best to extract word strings from a 
line = infile.readline()  

I wish to quickly check the first word of 
each line of a text file. 

Indeed, How do I break a lineinput() line 
into component words (separate by spaces etc) ?

Should I be looking at; 
Re Parser Slice StringIO ? 


Any help appreciated. 




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


Re: getting words from readline

2005-09-11 Thread Adam

Ouch.  That is simple with .split 

I must have got confused amongst 
slice re etc. searching searching. 

Thanks folks.  Painless. 

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


Font size

2005-02-15 Thread Adam
Please help me.
How do you clear the screen and then display a number with an enlarged font 
size (about 300).
Adam. 


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


Re: Font size

2005-02-15 Thread Adam

"BOOGIEMAN" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Tue, 15 Feb 2005 21:22:43 GMT, Adam wrote:
>
>> Please help me.
>> How do you clear the screen and then display a number with an enlarged 
>> font
>> size (about 300).
>> Adam.
>
> To clear screen in windows :
>
> #at the beggining of the program
> import os
>
> #when you want to clear the screen
> os.system("cls")

Thanks
I'll try that.
Adam. 


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


Re: Font size

2005-02-16 Thread Adam

"Adam" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> "BOOGIEMAN" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> On Tue, 15 Feb 2005 21:22:43 GMT, Adam wrote:
>>
>>> Please help me.
>>> How do you clear the screen and then display a number with an enlarged 
>>> font
>>> size (about 300).
>>> Adam.
>>
>> To clear screen in windows :
>>
>> #at the beggining of the program
>> import os
>>
>> #when you want to clear the screen
>> os.system("cls")
>
> Thanks
> I'll try that.
> Adam.
>
Unfortunately that didn't work.
Here's what I'm trying to do.
We are running a numbers game at our retirement village and using a roulette 
wheel to generate the numbers. but this wheel is only about 12 in diameter 
and is little more than a toy. So we came up with the idea of using a random 
number generator to generate numbers from 0 to 36 and display them in large 
figures on my laptop. This is for the benefit of those people who are hard 
of hearing. They like to see what is happening.
I was an RPG programmer before retirement but am new to Python. So I used 
the following code to generate the numbers but I don't know how to display 
them in large figures (about 3 ins high) or get rid of the idle text.

from random import randint
rand = randint(0,36)
print rand

my os = XP
Can you help?
Adam. 


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


Re: Font size

2005-02-17 Thread Adam

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Adam" <[EMAIL PROTECTED]> wrote:
>
>> So we came up with the idea of using a random  number generator to
>> generate numbers from 0 to 36 and display them in large figures on my
>> laptop. This is for the benefit of those people who are hard of hearing.
>> They like to see what is happening.
>
> here's one way to do this:
>
> from Tkinter import *
> from random import randint
> from time import sleep
>
> def update(event=None):
>  for i in range(10):
>label.config(text=str(randint(0,36)))
>label.update()
>sleep(0.05)
>
> # create a maximized window
> root = Tk()
> root.wm_state("zoomed")
> root.title("my roulette wheel")
>
> # 80% of the screen height
> height = int(root.winfo_screenheight() * 0.8)
>
> # create label (use negative font size for size in pixels)
> label = Label(root, font="Arial " + str(-height), bg="gold")
> label.pack(fill=BOTH, expand=1)
>
> # click anywhere in window to pick a new number
> root.bind("", update)
>
> update() # display first number
>
> mainloop()
>
> (tweak as necessary)
>
> 
>
>
I thank all of you.
I will try each one of these suggestions.
Adam. 


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


Re: Font size

2005-02-18 Thread Adam
Thanks Fredrik,
I got your program running (with a couple of tweaks) with just a quarter of 
an hour to spare before using it at our happy hour yesterday.
The old ladies loved it.
I can now adapt it for bingo.
Thanking you
Adam. 


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


Python consultant

2004-12-07 Thread Adam
I know Java and C very well, and I've also decided to learn python. I
am currently coding a web based massively multiplayer Nation Simulation
with Python(that's how I learn languages, I undertake fairly large
projects.) My friend and I have written a lot of it, and we started a
project on sourceforge.
Since we are "noobs" to Python, we'd like a consultant of some sort.
Mainly we need someone to help us with the GUI. And the database stuff.

http://sourceforge.net/projects/creo/

And our forum to post code and suggestions:
http://s4.invisionfree.com/Creo_Tellus/


 Thankyou.

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


Re: Python SSL Socket issue

2005-04-20 Thread adam
Try

con.connect()

before the first putrequest

-adam

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


Re: Redhat 9, Python 2.4.1, CGIHTTPServer problem

2005-04-20 Thread adam
It might not be the script, but might be the environment. I've been
burned by something similar in the past when I had my CGI script in my
home dir (default +r) and didnt have the permissions correct on the
dir. Not only does the script have to be +r +x, but the dir it is in
has to be as well for the apache user.

-adam

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


Code review?

2014-01-13 Thread Adam
Hey all.  New to the list.  I’m working on a web app with 2.6 and Flask.  I’m 
still relatively new to python.  Is there a chance to get a code review from 
anyone?  I really want someone to just tear up my code and tell me how to 
increase my efficiency and what I’m doing wrong (and how to upload images via a 
form in Flask, but that’s another story).

Happy coding
Adam
-- 
https://mail.python.org/mailman/listinfo/python-list


crash while using PyCharm / Python3

2016-03-18 Thread Adam

Host OS:Ubuntu Desktop 14.04 LTS / Unity

System crashed while using PyCharm / Python3.
Booting takes forever and stuck at the purple screen with
the Ubuntu logo and the five dots cycling.
How to fix?


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Adam"  wrote in message 
news:ncikss$tks$1...@news.albasani.net...
>
> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>
> System crashed while using PyCharm / Python3.
> Booting takes forever and stuck at the purple screen with
> the Ubuntu logo and the five dots cycling.
> How to fix?
>

So, I tried Ubuntu repair methods suggested here...

How to Fix an Ubuntu System When It Won't Boot
http://www.howtogeek.com/196740/how-to-fix-an-ubuntu-system-when-it-wont-boot/
GRUB Boot Loader is accessible but using the recovery mode did not help.
It hangs with "Loading extension GLX" but I forget which command I used.

Then, I tried to...

Reinstall Ubuntu While Keeping Files and Programs

but, I am instead given the following options...
===
This computer currently has Ubuntu 14.04.4 LTS on it.  What would you like 
to do?

- Erase Ubuntu 14.04.4 LTS and reinstall
Warning: This will delete all your Ubuntu 14.04.4 LTS programs, 
documents, photos...
- Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS
Documents, music, and other personal files will be kept.  You can choose 
which operating system...
- Erase disk and install Ubuntu
- Something else
===

Perhaps, "Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS" is the 
safest ? 


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Adam"  wrote in message 
news:ncp8r1$ofd$1...@news.albasani.net...
>
> "Adam"  wrote in message 
> news:ncikss$tks$1...@news.albasani.net...
>>
>> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>>
>> System crashed while using PyCharm / Python3.
>> Booting takes forever and stuck at the purple screen with
>> the Ubuntu logo and the five dots cycling.
>> How to fix?
>>
>
> So, I tried Ubuntu repair methods suggested here...
>
> How to Fix an Ubuntu System When It Won't Boot
> http://www.howtogeek.com/196740/how-to-fix-an-ubuntu-system-when-it-wont-boot/
> GRUB Boot Loader is accessible but using the recovery mode did not help.
> It hangs with "Loading extension GLX" but I forget which command I used.

I remember now, failsafeX and Ctrl+Alt+F1 from here...
http://askubuntu.com/questions/141606/how-to-fix-the-system-is-running-in-low-graphics-mode-error

But, still getting "The system is running in low-graphics mode" error.  How 
to fix?
The problem does not appear to be due to low disk space.
At least, it's no longer stuck at the purple screen with
the Ubuntu logo and the five dots cycling.
So, I will hold off reinstalling Ubuntu for now.


>
> Then, I tried to...
>
> Reinstall Ubuntu While Keeping Files and Programs
>
> but, I am instead given the following options...
> ===
> This computer currently has Ubuntu 14.04.4 LTS on it.  What would you like 
> to do?
>
> - Erase Ubuntu 14.04.4 LTS and reinstall
>Warning: This will delete all your Ubuntu 14.04.4 LTS programs, 
> documents, photos...
> - Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS
>Documents, music, and other personal files will be kept.  You can 
> choose which operating system...
> - Erase disk and install Ubuntu
> - Something else
> ===
>
> Perhaps, "Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS" is the 
> safest ?
> 


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Dirk T. Verbeek"  wrote in message 
news:56f03080$0$5924$e4fe5...@news.xs4all.nl...
> Op 21-03-16 om 17:51 schreef Adam:
>> "Adam"  wrote in message
>> news:ncikss$tks$1...@news.albasani.net...
>>>
>>> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>>>
>>> System crashed while using PyCharm / Python3.
>>> Booting takes forever and stuck at the purple screen with
>>> the Ubuntu logo and the five dots cycling.
>>> How to fix?
>>>
>>
>> So, I tried Ubuntu repair methods suggested here...
>>
>> How to Fix an Ubuntu System When It Won't Boot
>> http://www.howtogeek.com/196740/how-to-fix-an-ubuntu-system-when-it-wont-boot/
>> GRUB Boot Loader is accessible but using the recovery mode did not help.
>> It hangs with "Loading extension GLX" but I forget which command I used.
>>
>> Then, I tried to...
>>
>> Reinstall Ubuntu While Keeping Files and Programs
>>
>> but, I am instead given the following options...
>> ===
>> This computer currently has Ubuntu 14.04.4 LTS on it.  What would you 
>> like
>> to do?
>>
>> - Erase Ubuntu 14.04.4 LTS and reinstall
>>  Warning: This will delete all your Ubuntu 14.04.4 LTS programs,
>> documents, photos...
>> - Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS
>>  Documents, music, and other personal files will be kept.  You can 
>> choose
>> which operating system...
>> - Erase disk and install Ubuntu
>> - Something else
>> ===
>>
>> Perhaps, "Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS" is the
>> safest ?
>>
>>
> It's easy to do a reinstall without wiping documents and application 
> configurations/settings PROVIDING you have a separate / (root) and /home 
> partition.

Yes, I have a separate /home partition.


>
> During partition you select Manual partitioning and assign the existing 
> partitions being VERY careful to NOT format the existing /home.
>
> But / where the OS and all applications reside will need to be 
> formatted/deleted/overwritten.
>
> Keeping the configuration on your /home might cause the old error to be 
> included in the new install...
>
> Although, you error seems to be the system, not the applications.

I think it's a system issue as well.  The problem happened almost right 
after
creating a python3 virtual environment using PyCharm.
There were two checkboxes (both "Inherit global site-packages" and
"Make available to all projects" were checked).
Can this be the problem ? 


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Dirk T. Verbeek"  wrote in message 
news:56f03080$0$5924$e4fe5...@news.xs4all.nl...
> Op 21-03-16 om 17:51 schreef Adam:
>> "Adam"  wrote in message
>> news:ncikss$tks$1...@news.albasani.net...
>>>
>>> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>>>
>>> System crashed while using PyCharm / Python3.
>>> Booting takes forever and stuck at the purple screen with
>>> the Ubuntu logo and the five dots cycling.
>>> How to fix?
>>>
>>
>> So, I tried Ubuntu repair methods suggested here...
>>
>> How to Fix an Ubuntu System When It Won't Boot
>> http://www.howtogeek.com/196740/how-to-fix-an-ubuntu-system-when-it-wont-boot/
>> GRUB Boot Loader is accessible but using the recovery mode did not help.
>> It hangs with "Loading extension GLX" but I forget which command I used.
>>
>> Then, I tried to...
>>
>> Reinstall Ubuntu While Keeping Files and Programs
>>
>> but, I am instead given the following options...
>> ===
>> This computer currently has Ubuntu 14.04.4 LTS on it.  What would you 
>> like
>> to do?
>>
>> - Erase Ubuntu 14.04.4 LTS and reinstall
>>  Warning: This will delete all your Ubuntu 14.04.4 LTS programs,
>> documents, photos...
>> - Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS
>>  Documents, music, and other personal files will be kept.  You can 
>> choose
>> which operating system...
>> - Erase disk and install Ubuntu
>> - Something else
>> ===
>>
>> Perhaps, "Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS" is the
>> safest ?
>>
>>
> It's easy to do a reinstall without wiping documents and application 
> configurations/settings PROVIDING you have a separate / (root) and /home 
> partition.
>
> During partition you select Manual partitioning and assign the existing 
> partitions being VERY careful to NOT format the existing /home.
>
> But / where the OS and all applications reside will need to be 
> formatted/deleted/overwritten.

I guess I can do something like...

$ dpkg --get-selections \*|awk '{print $1}'>~/package_list
$ cat ~/package_list|sudo xargs -l1 aptitude reinstall

to reinstall packages that were installed after installing Ubuntu.

There ought to be a way to just reinstall the graphics subsystem rather than
an all-or-none installation approach.


>
> Keeping the configuration on your /home might cause the old error to be 
> included in the new install...
>
> Although, you error seems to be the system, not the applications. 


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Jonathan N. Little"  wrote in message 
news:ncpjj0$7ug$1...@dont-email.me...
> Adam wrote:
>> There ought to be a way to just reinstall the graphics subsystem rather 
>> than
>> an all-or-none installation approach.
>
> Yes you can. Did it for a borked install of the nVidia driver. reference 
> this:
>
> <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx>

Thanks, even after doing the following...
Problem: Need to purge -fglrx
Typically, the following manual commands will properly uninstall -fglrx:


  sudo apt-get remove --purge xorg-driver-fglrx fglrx*
  sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri 
xserver-xorg-core
  sudo dpkg-reconfigure xserver-xorgI still get that dreaded "The system is 
running in low-graphics mode" error.
And, recovery mode failsafeX and Ctrl+Alt+F1 hangs with the following...


Initializing built-in extension MIT-SCREEN-SAVER
Initializing built-in extension DOUBLE-BUFFER
Initializing built-in extension RECORD
Initializing built-in extension DPMS
Initializing built-in extension Present
Initializing built-in extension DRI3
Initializing built-in extension X-Resource
Initializing built-in extension XVideo
Initializing built-in extension XVideo-MotionCompensation
Initializing built-in extension SELinux
Initializing built-in extension XFree86-VidModeExtension
Initializing built-in extension XFree86-DGA
Initializing built-in extension XFree86-DRI
Initializing built-in extension DRI2
Loading extension GLX



>
> -- 
> Take care,
>
> Jonathan
> ---
> LITTLE WORKS STUDIO
> http://www.LittleWorksStudio.com 


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Adam"  wrote in message 
news:ncprqb$tl9$1...@news.albasani.net...
>
> "Jonathan N. Little"  wrote in message 
> news:ncpjj0$7ug$1...@dont-email.me...
>> Adam wrote:
>>> There ought to be a way to just reinstall the graphics subsystem rather 
>>> than
>>> an all-or-none installation approach.
>>
>> Yes you can. Did it for a borked install of the nVidia driver. reference 
>> this:
>>
>> <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx>
>
> Thanks, even after doing the following...
>
> Problem: Need to purge -fglrx
>
> Typically, the following manual commands will properly uninstall -fglrx:
>
>  $ sudo apt-get remove --purge xorg-driver-fglrx fglrx*
>  $ sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri 
> xserver-xorg-core
>  $ sudo dpkg-reconfigure xserver-xorg
>
> I still get that dreaded "The system is running in low-graphics mode" 
> error.
> And, recovery mode failsafeX and Ctrl+Alt+F1 hangs with the following...
>
>
> Initializing built-in extension MIT-SCREEN-SAVER
> Initializing built-in extension DOUBLE-BUFFER
> Initializing built-in extension RECORD
> Initializing built-in extension DPMS
> Initializing built-in extension Present
> Initializing built-in extension DRI3
> Initializing built-in extension X-Resource
> Initializing built-in extension XVideo
> Initializing built-in extension XVideo-MotionCompensation
> Initializing built-in extension SELinux
> Initializing built-in extension XFree86-VidModeExtension
> Initializing built-in extension XFree86-DGA
> Initializing built-in extension XFree86-DRI
> Initializing built-in extension DRI2
> Loading extension GLX
> 
>

After trying the following...

http://askubuntu.com/questions/577093/how-to-install-gnome-desktop

$ sudo apt-get update
$ sudo apt-get install gnome-shell


http://tipsonubuntu.com/2014/06/06/change-display-manager-ubuntu-14-04/

$ sudo dpkg-reconfigure lightdm

I am now able to login.  But,
not sure what happened to the "lightdm" display manager.
I am now using "gdm" display manager.


>
>>
>> -- 
>> Take care,
>>
>> Jonathan
>> ---
>> LITTLE WORKS STUDIO
>> http://www.LittleWorksStudio.com
>
> 


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


Re: crash while using PyCharm / Python3

2016-03-21 Thread Adam

"Adam"  wrote in message 
news:ncpev8$51d$1...@news.albasani.net...
>
> "Dirk T. Verbeek"  wrote in message 
> news:56f03080$0$5924$e4fe5...@news.xs4all.nl...
>> Op 21-03-16 om 17:51 schreef Adam:
>>> "Adam"  wrote in message
>>> news:ncikss$tks$1...@news.albasani.net...
>>>>
>>>> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>>>>
>>>> System crashed while using PyCharm / Python3.
>>>> Booting takes forever and stuck at the purple screen with
>>>> the Ubuntu logo and the five dots cycling.
>>>> How to fix?
>>>>
>>>
>>> So, I tried Ubuntu repair methods suggested here...
>>>
>>> How to Fix an Ubuntu System When It Won't Boot
>>> http://www.howtogeek.com/196740/how-to-fix-an-ubuntu-system-when-it-wont-boot/
>>> GRUB Boot Loader is accessible but using the recovery mode did not help.
>>> It hangs with "Loading extension GLX" but I forget which command I used.
>>>
>>> Then, I tried to...
>>>
>>> Reinstall Ubuntu While Keeping Files and Programs
>>>
>>> but, I am instead given the following options...
>>> ===
>>> This computer currently has Ubuntu 14.04.4 LTS on it.  What would you 
>>> like
>>> to do?
>>>
>>> - Erase Ubuntu 14.04.4 LTS and reinstall
>>>  Warning: This will delete all your Ubuntu 14.04.4 LTS programs,
>>> documents, photos...
>>> - Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS
>>>  Documents, music, and other personal files will be kept.  You can 
>>> choose
>>> which operating system...
>>> - Erase disk and install Ubuntu
>>> - Something else
>>> ===
>>>
>>> Perhaps, "Install Ubuntu 14.04.4 LTS alongside Ubuntu 14.04.4 LTS" is 
>>> the
>>> safest ?
>>>
>>>
>> It's easy to do a reinstall without wiping documents and application 
>> configurations/settings PROVIDING you have a separate / (root) and /home 
>> partition.
>>
>> During partition you select Manual partitioning and assign the existing 
>> partitions being VERY careful to NOT format the existing /home.
>>
>> But / where the OS and all applications reside will need to be 
>> formatted/deleted/overwritten.
>
> I guess I can do something like...
>
> $ dpkg --get-selections \*|awk '{print $1}'>~/package_list
> $ cat ~/package_list|sudo xargs -l1 aptitude reinstall
>
> to reinstall packages that were installed after installing Ubuntu.
>
> There ought to be a way to just reinstall the graphics subsystem rather 
> than
> an all-or-none installation approach.
>

Sure glad I did not reinstall Ubuntu.  Whew!!


>
>>
>> Keeping the configuration on your /home might cause the old error to be 
>> included in the new install...
>>
>> Although, you error seems to be the system, not the applications.
>
> 


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


Re: crash while using PyCharm / Python3

2016-03-22 Thread Adam

"Jonathan N. Little"  wrote in message 
news:ncqc7j$na1$1...@dont-email.me...
> Adam wrote:
>> "Adam"  wrote in message
>> news:ncprqb$tl9$1...@news.albasani.net...
>>>
>>> "Jonathan N. Little"  wrote in message
>>> news:ncpjj0$7ug$1...@dont-email.me...
>>>> Adam wrote:
>>>>> There ought to be a way to just reinstall the graphics subsystem 
>>>>> rather
>>>>> than
>>>>> an all-or-none installation approach.
>>>>
>>>> Yes you can. Did it for a borked install of the nVidia driver. 
>>>> reference
>>>> this:
>>>>
>>>> <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx>
>>>
>>> Thanks, even after doing the following...
>>>
>>> Problem: Need to purge -fglrx
>>>
>>> Typically, the following manual commands will properly uninstall -fglrx:
>>>
>>>   $ sudo apt-get remove --purge xorg-driver-fglrx fglrx*
>>>   $ sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri
>>> xserver-xorg-core
>>>   $ sudo dpkg-reconfigure xserver-xorg
>>>
>>> I still get that dreaded "The system is running in low-graphics mode"
>>> error.
>>> And, recovery mode failsafeX and Ctrl+Alt+F1 hangs with the following...
>>>
>>> 
>>> Initializing built-in extension MIT-SCREEN-SAVER
>>> Initializing built-in extension DOUBLE-BUFFER
>>> Initializing built-in extension RECORD
>>> Initializing built-in extension DPMS
>>> Initializing built-in extension Present
>>> Initializing built-in extension DRI3
>>> Initializing built-in extension X-Resource
>>> Initializing built-in extension XVideo
>>> Initializing built-in extension XVideo-MotionCompensation
>>> Initializing built-in extension SELinux
>>> Initializing built-in extension XFree86-VidModeExtension
>>> Initializing built-in extension XFree86-DGA
>>> Initializing built-in extension XFree86-DRI
>>> Initializing built-in extension DRI2
>>> Loading extension GLX
>>> 
>>>
>>
>> After trying the following...
>>
>> http://askubuntu.com/questions/577093/how-to-install-gnome-desktop
>>
>> $ sudo apt-get update
>> $ sudo apt-get install gnome-shell
>>
>>
>> http://tipsonubuntu.com/2014/06/06/change-display-manager-ubuntu-14-04/
>>
>> $ sudo dpkg-reconfigure lightdm
>
> Not sure about ATI, but when you purge the nVidia driver it takes Unity 
> with it so I had to reinstall unity-desktop afterwards. If you want 
> lightdm but are now using gdm, maybe it happened because unity-desktop was 
> uninstalled and you just installed gnome-shell, your can reset:
>
> sudo dpkg-reconfigure gdm
>
> and select lightdm from the list.
>

Thanks, but why fix if it ain't broke?:-)


>
> -- 
> Take care,
>
> Jonathan
> ---
> LITTLE WORKS STUDIO
> http://www.LittleWorksStudio.com 


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


Re: crash while using PyCharm / Python3

2016-03-22 Thread Adam

"Jonathan N. Little"  wrote in message 
news:ncqd2d$pab$1...@dont-email.me...
> Adam wrote:
>> Sure glad I did not reinstall Ubuntu.  Whew!!
>
> Unless you really-really-really screw things up, you usually do not have 
> to. Linux is not Windows ;-) Even if you had to, with /home on its own 
> partition a reinstall would not have been an issue, you just have to 
> choose the "Something Else" on partitioning and only format the "/" and 
> set the "/home" partition mount point and NOT FORMAT it.

I would have to install additional apps all over again.  Ick!!


>
> A tip: If you use gparted or e2label and give partitions labels. Makes 
> moving partitions and data easier...
>
> sda1 "12.04-root"
> sda5 "old-home"
>
> sdb1 "14.04-root"
> sdb5 "new-home"

Thanks, I'll keep this in mind.


>
> So from a live session when I mount both drives it is easy to keep things 
> straight when I copy my profiles from old drive on sda to new drive with 
> newer version of Ubuntu on sdb...
>
> -- 
> Take care,
>
> Jonathan
> ---
> LITTLE WORKS STUDIO
> http://www.LittleWorksStudio.com 


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


Re: crash while using PyCharm / Python3

2016-03-22 Thread Adam

"Big Bad Bob"  wrote in message 
news:mp6dnavahbnh6gzlnz2dnuu7-y_nn...@earthlink.com...
> On 03/21/16 17:23, Adam so wittily quipped:
>> "Adam"  wrote in message
>> news:ncprqb$tl9$1...@news.albasani.net...
>>>
>>> "Jonathan N. Little"  wrote in message
>>> news:ncpjj0$7ug$1...@dont-email.me...
>>>> Adam wrote:
>>>>> There ought to be a way to just reinstall the graphics subsystem 
>>>>> rather
>>>>> than
>>>>> an all-or-none installation approach.
>>>>
>>>> Yes you can. Did it for a borked install of the nVidia driver. 
>>>> reference
>>>> this:
>>>>
>>>> <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx>
>>>
>>> Thanks, even after doing the following...
>>>
>>> Problem: Need to purge -fglrx
>>>
>>> Typically, the following manual commands will properly uninstall -fglrx:
>>>
>>>  $ sudo apt-get remove --purge xorg-driver-fglrx fglrx*
>>>  $ sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri
>>> xserver-xorg-core
>>>  $ sudo dpkg-reconfigure xserver-xorg
>>>
>>> I still get that dreaded "The system is running in low-graphics mode"
>>> error.
>>> And, recovery mode failsafeX and Ctrl+Alt+F1 hangs with the following...
>>>
>>>
>>> Initializing built-in extension MIT-SCREEN-SAVER
>>> Initializing built-in extension DOUBLE-BUFFER
>>> Initializing built-in extension RECORD
>>> Initializing built-in extension DPMS
>>> Initializing built-in extension Present
>>> Initializing built-in extension DRI3
>>> Initializing built-in extension X-Resource
>>> Initializing built-in extension XVideo
>>> Initializing built-in extension XVideo-MotionCompensation
>>> Initializing built-in extension SELinux
>>> Initializing built-in extension XFree86-VidModeExtension
>>> Initializing built-in extension XFree86-DGA
>>> Initializing built-in extension XFree86-DRI
>>> Initializing built-in extension DRI2
>>> Loading extension GLX
>>> 
>>>
>>
>> After trying the following...
>>
>> http://askubuntu.com/questions/577093/how-to-install-gnome-desktop
>>
>> $ sudo apt-get update
>> $ sudo apt-get install gnome-shell
>>
>>
>> http://tipsonubuntu.com/2014/06/06/change-display-manager-ubuntu-14-04/
>>
>> $ sudo dpkg-reconfigure lightdm
>>
>> I am now able to login.  But,
>> not sure what happened to the "lightdm" display manager.
>> I am now using "gdm" display manager.
>
> if you're able to boot up by changing things *like* the display manager,
> you might want to take a look at the X11 configuration directly.  Adding
> "more cruft" to your system (i.e. gdm) isn't necessarily going to 'fix'
> a problem that's related to the X11 configuration.
>
> [it's one reason why I generally prefer to boot to command line rather
> than into a GUI for a typical linux install]
>
> as an example, you could save your xorg.conf file
>  /etc/X11/xorg.conf

No such file on my system.  Is it even needed ?


>
> and generate a new one, using 'xorg -configure' (as root).
>
> I'm guessing that when you installed the 'PyCharm' package, "some other
> dependent package" did something undesirable to your xorg.conf file.

I no longer think PyCharm / Python3 is the cause of the crash.
It was just a coincidence.

Search for "lightdm problem ubuntu 14.04"


>
> That would MOST CERTAINLY cause a hang during the desktop startup.

lightdm was failing.


>
> it might also be fixable by re-configuring your installed packages,
> rather than a full-blown re-install from scratch.
>
> dpkg-reconfigure -a
>
> [the man page warns "it may take a long time" - yeah, probably will]
>
>
> Keep in mind that adding gdm afterwards *might* have done the
> 'reconfigure' on the problem package(s) already.  So adding 'gdm'
> instead of whatever login manager you were using before [along with all
> of its dependent packages] would most likely have forced "the problem
> package" to re-configure.  That very well might have "fixed" the problem
> on its own.  So my suggestion here would be to remove this 'new' package
> and see if the problem comes back.  Most likely it won't.
>

Thanks, but it's working fine now.:-)


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


Re: crash while using PyCharm / Python3

2016-03-22 Thread Adam

"Jonathan N. Little"  wrote in message 
news:ncrg2v$jo$2...@dont-email.me...
> Adam wrote:
>> Thanks, but why fix if it ain't broke?:-)
>
> No reason to.

Yup, I agree.


>
> -- 
> Take care,
>
> Jonathan
> ---
> LITTLE WORKS STUDIO
> http://www.LittleWorksStudio.com 


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


Re: crash while using PyCharm / Python3

2016-03-23 Thread Adam

"Adam"  wrote in message 
news:ncikss$tks$1...@news.albasani.net...
>
> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>
> System crashed while using PyCharm / Python3.
> Booting takes forever and stuck at the purple screen with
> the Ubuntu logo and the five dots cycling.
> How to fix?
>

Searching for this thread in a browser lead to
the code.activestate.com website where
I see posts from Daniel Wilcox.
But, in my newsreader, I do not see his posts,
which is why his posts are not getting any response.
Daniel, how/where are you responding to this thread?


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


application console with window

2015-01-07 Thread adam
Is in here maybe someone who speak Polish?

I would like to write application witch looks like this 
http://linuxiarze.pl/obrazy/internet1/ceni1.png

I'm looking for some libs, tutorials, or other informations.
I'm searching this informations for python3.

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


Re: application console with window

2015-01-08 Thread adam
Hej, no właśnie niechodzi o przeniesienie do okienek tylko jeśli znasz taki 
program jak np fk dla dos-a to chodzi mi o taki efekt. Czyli aplikacja 
konsolowa z pseudo okienkami.

Adam

jacek pozniak wrote:

> adam wrote:
> 
>> Is in here maybe someone who speak Polish?
>> 
>> I would like to write application witch looks like this
>> http://linuxiarze.pl/obrazy/internet1/ceni1.png
> Jeśli chodzi Ci o przeniesienie na wersję okienkową to na przykład:
> tkinter.
> 
> jp
> 
>> 
>> I'm looking for some libs, tutorials, or other informations.
>> I'm searching this informations for python3.
>> 
>> adam

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


Re: application console with window

2015-01-08 Thread adam
Dennis Lee Bieber wrote:

> On Wed, 07 Jan 2015 22:17:09 +0100, adam 
> declaimed the following:
> 
>>Is in here maybe someone who speak Polish?
>>
>>I would like to write application witch looks like this
>>http://linuxiarze.pl/obrazy/internet1/ceni1.png
>>
> Based upon the image, that is mainly an addressable console application
> with a line-draw character set. Something maybe possible using MS-DOS 3.x
> 
> What OS are you using?
Linux, fedora, debian, centOS, maybe windows 7 or 8.1
> 
>>I'm looking for some libs, tutorials, or other informations.
> 
> Check the documentation for the Python curses library.
> 
Thank you

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


Re: application console with window

2015-01-08 Thread adam
Emil Oppeln-Bronikowski wrote:

> On Wed, Jan 07, 2015 at 10:17:09PM +0100, adam wrote:
>> Is in here maybe someone who speak Polish?
> 
> Mówię, a raczej piszę.
> 
>> I'm looking for some libs, tutorials, or other informations.
> 
> This is terminal application using (n)curses or smilar library that helps
> you draw & interact with windows, forms and other widgets.
> 
> You can use curses library, but it's a little big hairy. There are a few
> extra libraries that make writing "full-screen" terminal application a
> breeze.
> 
> The most popular one (…and complete?) is urwid, and there are pages of
> tutorial once you google for it.
> 
> PS. if you need some help feel free to e-mail me off-list.
> 
thank you,

I just learn python. If you write in Polish it will be easier for me to 
explain any problem, because my English is very thin.

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


Re: application console with window

2015-01-08 Thread adam
Emil Oppeln-Bronikowski wrote:

> On Thu, Jan 08, 2015 at 05:18:07PM +0100, adam wrote:
> 
>> I just learn python.
> 
> We all do. It's a constant process.
> 
>> If you write in Polish it will be easier for me to
>> explain any problem, because my English is very thin.
> 
> I don't really want to force others to read Polish, hit me private if you
> have any questions.
> 

Ok no problem
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proposal: Inline Import

2005-12-12 Thread adam
When I'm feeling too lazy to do imports while moving large blocks of
code, I use this little hack. It lets me proceed with checking whether
the move does what I wanted and at the end I fix the imports and remove
the try/except wrapper. I think it would achieve your desired result
and not have an impact on the language itself.

try:
#your main code here
print string.upper("blah")
except NameError, error_value:
mod_name = error_value.args[0][error_value.args[0].find("'") +
1:error_value.args[0].rfind("'")]
try:
__import__(mod_name)
print "imported %s" % mod_name
except:
print "NameError: %s" % error_value.args[0]
pass

-adam

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


newbie graphing recommendations ?

2006-07-02 Thread Adam

Where should a py newbie start to do some 2D graphs on screen ? 

PythonGraphApi, 
Gato, looks interesting 
pygraphlib, 
matplotlib, 

is there a best native Python place to start ? 



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


Re: Learning to program in Python

2007-01-05 Thread Adam

jbchua wrote:

> Hello everybody.
>
> I am an Electrical Engineering major and have dabbled in several
> languages such as Python, C, and Java in my spare time because of my
> interest in programming. However, I have not done any practical
> programming because I have no idea where to get started. I taught
> myself these languages basically by e-tutorials and books. This makes
> me feel as if I don't really know how to implement these languages.
> Does anybody have any advice on where to start applying my limited
> knowledge practically in order to advance my learning?

I am just starting to learn to program as well. (In my spare time.) The
advice about deciding on a goal, a project to work on, is good.

I have just got through the basics section in this guide here
(http://www.freenetpages.co.uk/hp/alan.gauld/), which I found very
useful for beginners and the address book example you build up shows
the python in practice.

Once I had learnt about file inp/out I decided to make a program that
would split a file in half for email and then could be used to join
them together again. This helped me get used to most of what I had
learnt in the beginner section.

Also don't forget the Python.org documentation it's very helpful and is
a great companion to most the 3rd party tutorials around.

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


Pyro problems...

2006-01-23 Thread adam

I'm using Pyro to develop a distribuited system

running my integration test suite I've found a strange
behaviour

it seems that whenever I have a failed resolve or unregister on
a name server, the name server acts normally during its life
span, but when I shut it down... something remains up...

if, afterwards, i lookup for a name server python freezes
and if i try to start a new name server, the port look occupied

is this a Pyro issue? or is that just me, that I've lost something
important?

i'll attach the code that causes the freeze

thanks!

Vieri


***


print('test_pyro_bug')
timeout = 10
#init pyro
Pyro.core.initServer(0)
Pyro.core.initClient(0)
#start name server
ns_host = 'localhost'
ns_port = 9090
name_server_starter = Pyro.naming.NameServerStarter()
name_server_thread = threading.Thread(
target = name_server_starter.start,
args = (ns_host, ns_port))
name_server_thread.setDaemon(True)
name_server_thread.start()
name_server_starter.waitUntilStarted(timeout)
#locate name server
locator = Pyro.naming.NameServerLocator()
name_server = locator.getNS(ns_host, ns_port)
name_server.createGroup( "my_group" )
#init daemon
daemon = Pyro.core.Daemon()
daemon.useNameServer(name_server)
daemon_thread = threading.Thread(
target = daemon.requestLoop,
args = ())
daemon_thread.setDaemon(True)
daemon_thread.start()
#try to unregisater a non existent object
dummy_name = "my_group" + ".dummy"
dummy = _DummyRemote()
daemon.connect(dummy, dummy_name)
try:
name_server.unregister(dummy_name + "not found")
except Pyro.core.NamingError:
pass
#shutdown daemon
daemon.shutdown()
daemon = None
daemon_thread.join(timeout)
daemon_thread = None
#shutdown name server
name_server._shutdown()
name_server_thread.join(timeout)
name_server_thread = None
#locate name server
locator = Pyro.naming.NameServerLocator()
##freezes here!
self.failUnlessRaises(
Pyro.core.ProtocolError,
locator.getNS, ns_host, ns_port)




Vieri del Bianco
CEFRIEL · Politecnico di Milano
Via Fucini, 2 · 20133 Milano (Italy)
t: +39 0223954355
e: [EMAIL PROTECTED]
w: http://www.cefriel.it


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


Re: seperating directories from files

2006-01-30 Thread adam
Check out the os.path (http://docs.python.org/lib/module-os.path.html)
module. It has the functions you are looking for.

-adam

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


Re: New to Tkinter GUI building

2007-03-02 Thread Adam
Thanks for the reply, will work with this tomorrow.

Adam

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


Re: Where I could find older python releases ?

2007-03-04 Thread Adam
On Mar 4, 9:52 am, 13 <[EMAIL PROTECTED]> wrote:
> Hello list,
>
> I have been searching the internet for python version 0.9.0 sources
> which had been posted to alt.sources list, but without any luck. Maybe
> someone has it available somewhere ?
>
> Thanks,
> Martins

http://www.python.org/download/

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


Re: Where I could find older python releases ?

2007-03-04 Thread Adam

Sorry jumped the gun a little there. Is this what you are looking for?
http://codespeak.net/download/py/py-0.9.0.zip

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


Logfile for my App not "rewriting"

2007-03-10 Thread Adam
lf):
os.remove('viFiles.txt')
print "logfile deleted"
self.txtBoxall.delete(1.0, tk.END)
self.txtBoxvi.delete(1.0, tk.END)
self.logfile = file("viFiles.txt", "w")
print "logfiles created"
self.dispresults = self.findallfiles(self.entDir.get())
index = 0
lenghth = 0
dif = 0
#Debug text input to command prompt
print "Dir: " + self.entDir.get() + "\n" + "Tar: " +
self.entTardir.get() + "\n" + "Char: " + self.entChar.get() + "\n"
for i in self.dispresults:
self.txtBoxall.insert(tk.END, i + "\n")
length = len(i) + len(self.entTardir.get()) -
len(self.entDir.get())
if length > int(self.entChar.get()):
index += 1
txt = "Violations: " + str(index)
dif = length - int(self.entChar.get())
self.logfile.write(i + "\n" + "\n" + "Violating File
#: " + str(index) + "\n" + "Shorten by: " + str(dif) + "\n" + "\n" +
"-" + "\n")
self.txtBoxvi.insert(tk.END, i + "\n")
self.labVi2.configure(text=txt)
self.logfile.close()

def quitEvent(self):
raise SystemExit


if __name__ == "__main__":
app = Theapp()
app.mainWindow.mainloop()

###End Code###

TIA
Adam

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


How to tell when a file is opened

2007-04-07 Thread Adam
Hello,

I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.

I will be wanting to watch all files on a server so this will be on
quite a large scale. So checking a directory on a loop for accesses
won't work.

Maybe some way to monitor the Open Files section of Computer
Management?

I check through Tim Golden's site but nothing jumped out at me.
Any pointers would be great.

Thanks,
Adam

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


Re: How to tell when a file is opened

2007-04-07 Thread Adam
On Apr 7, 5:09 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> Adam wrote:
> > I want to know if it possible to tell when a file is opened. However I
> > don't want it to be the last access time. I want to know how many
> > times a file opened so I can generate statistics of file usage.
>
> > I will be wanting to watch all files on a server so this will be on
> > quite a large scale. So checking a directory on a loop for accesses
> > won't work.
>
> > Maybe some way to monitor the Open Files section of Computer
> > Management?
>
> > I check through Tim Golden's site but nothing jumped out at me.
> > Any pointers would be great.
>
> I take it from the fact that you mention my site (and
> your reference to "Computer Management") that you're
> looking at Win32? It's always best to be explicit when
> you're asking for help; a lot of people on this list
> will be using Linux or Mac where the answers are
> probably very different.
>
> This is no small task you've set yourself! As far as I know,
> you're going to have to go down to the level of change journals
> for this kind of thing. (Search for "NTFS change journal").
>
> Although you might think: the filesystem knows when files are
> being accessed; can't I hook into that directly? I think the
> answer is: no. But I could be wrong.
>
> TJG

Sorry about not mentioning my platform.

What you mention looks promising. Will look into it. Like I said
knowing the last access time is not useful as I would have to be
constantly looping through the directory looking for changes.

Will look into NTFS change journals when I get some spare time.

Thanks for the reply.
Adam

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


Re: How to tell when a file is opened

2007-04-07 Thread Adam
On Apr 7, 8:02 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> Adam wrote:
> > On Apr 7, 5:09 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> > > Adam wrote:
> > > > I want to know if it possible to tell when a file is opened. However I
> > > > don't want it to be the last access time. I want to know how many
> > > > times a file opened so I can generate statistics of file usage.
>
> You may look into some tools like FileMon and Process Monitor 
> fromwww.sysinternals.com;I think that doing the processing in Python
> would slow down your system a lot (or not, just try!)
>
> --
> Gabriel Genellina

You see I was mainly hoping that python would not be doing the
processing per se. More that, as Tim put it, it would hook itself into
whatever monitors the shares to see when files are open and dump that
info somewhere (like a database or xml) then at a set time (at night
for example) Python would take that information collect it into
historical logs and update a web page with recent stats.

Obviously I have to check that the most vital part is even possible or
at least within my limit programming knowledge (which is why I ask
here.)

Adam

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


Re: Anyone has a nice "view_var" procedure ?

2007-01-15 Thread Adam

Stef Mientki wrote:

> hello,
>
> Is there some handy/ nice manner to view the properties of some variable ?
> As a newbie, I often want to see want all the properties of a var,
> and also some corner values (large arrays) etc.
>
> Probably it's not so difficult,
> but I don't see how to distinguish for example between a string and an
> array. An array has a shape, a string not etc.
>
>
> thanks,
> Stef Mientki

I am also a newbie so if this is not what you want I can't give much
more as of yet.

You can use type() to check what a Variable is. Usage:
#-Python Code-
>>> aVar = ["zero", 1, float(2)]
>>> type(aVar)

>>> type(aVar[0])

>>> type(aVar[1])

>>> type(aVar[2])

>>> if type(aVar[1]) == int:
print "test"

test
#-End Code---


There are also  function like len(). Usage:
#-Python Code-
>>> len(aVar)
3
>>> len(aVar[0])
4
#-End Code---

Hope this helps.
Adam

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


Re: Ip address

2007-01-28 Thread Adam
Hey,

This will get your IP address:

###Code
print socket.gethostbyaddr(socket.gethostname())
('compname', [], ['192.168.1.2'])
End Code

If you are wanting to to communicate over the internet you will have 
to get the IP of you rounter. So you will have to either find a way to 
talk to your router or try and use an online service like these other 
guys suggest.

On Jan 28, 9:54 am, Scripter47 <[EMAIL PROTECTED]> wrote:
> How do i get my ip address?
>
> in cmd.exe i just type "ipconfig" then it prints:
>   ...
>   IP-address . . . . . . . . . . . . . . . . . : 192.168.1.10
>   ...
> how can i do that in python??

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


Re: Conversion of string to integer

2007-01-29 Thread Adam


On Jan 29, 1:55 pm, "jupiter" <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I have a problem. I have a list which contains strings and numeric.
> What I want is to compare them in loop, ignore string and create
> another list of numeric values.


You can iterate over the list and use the type() function to work out 
what each entry and choose what to do with it.

type() works like so:
###Code###
>>> a = ["test", 1.25, "test2"]
>>> if type(a[2]) == str:
print "a string"


a string
>>>
###End Code###

Adam

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


Re: Walk thru each subdirectory from a top directory

2007-02-26 Thread Adam
On Feb 26, 9:28 pm, [EMAIL PROTECTED] wrote:
> i am trying to use python to walk thru each subdirectory from a top
> directory.  Here is my script:
>
> savedPagesDirectory = "/home/meryl/saved_pages/data"
>
> dir=open(savedPagesDirectory, 'r')
>
> for file in dir:
> if (isdir(file)):
> # get the full path of the file
> fileName = savedPagesDirectory + file + 'index.html'
> print fileName
>
> $ ./scripts/regressionTest.py
> Traceback (most recent call last):
>   File "./scripts/regressionTest.py", line 12, in ?
> dir=open(savedPagesDirectory, 'r')
> IOError: [Errno 21] Is a directory
>
> But I get the above error:
>
> Can you please tell me what did I do wrong?
>
> Thank you.

>From Alan Gaulds Tut.

>>> for t in os.walk('Root'):
...print t
...
('Root', ['D1', 'D2', 'D3'], ['FA.txt', 'FB.txt'])
('Root/D1', ['D1-1'], ['FC.txt'])
('Root/D1/D1-1', [], ['FF.txt'])
('Root/D2', [], ['FD.txt'])
('Root/D3', ['D3-1'], ['FE.txt'])
('Root/D3/D3-1', [], ['target.txt'])
>>>


This bit below is from one of my first programs as I'm currently
learning. It is designed to go form the root down and return the full
paths of everything it finds into a list. (I then check the reults for
files paths that exceed a certain length - but you don't need to know
that.)


def findallfiles(self, base):
self.results = []
for root,dirs,files in os.walk(base):
os.chdir(root)
self.scan = glob.glob("*")
for r in self.scan:
if root[-1] == "\\":
self.results.append(root + r)
else:
self.results.append(root + "\\" + r)
return self.results


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


Re: Walk thru each subdirectory from a top directory

2007-02-26 Thread Adam
Whoops, the first bit of my reply ended up in the quoted text. See
above.

Adam

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


New to Tkinter GUI building

2007-02-28 Thread Adam
Hey,

I'm pretty new to programming. Been trying to learn using Python.
The code I'm struggling with is for my GUI.

I'm am having trouble getting this to display the way I want with the
grid manager. Can anybody tell me what I am doing wrong? I hope you
can tell what look I'm trying to achieve from the code as its hard to
explain.

I think my main questions are:
1. How can I get the Window to be sized the way I want it?
2. How can I get the Scrollbars to fill the side of the text box
instead of being small? (like .pack(fill= tk.Y)

##Code###

#file/path finder
#indentation value 4
import os,glob
import Tkinter as tk

# Class to create the Application and UI
class Theapp:
def __init__(self):
# Create GUI parts. Will allign later with grid
self.top = tk.Tk()
self.mainWindow = tk.Frame(self.top, width=700, height=400)
self.labAll = tk.Label(self.mainWindow, text="All Files/
Folders:")
self.labVi = tk.Label(self.mainWindow, text="Violating Files/
Folders:")

#Create a sub-frame containing textbox and scrollbar for All
files scanned display
self.allTxtf = tk.Frame(self.mainWindow, width=699,
height=164)
self.scrlr1 = tk.Scrollbar(self.allTxtf)
self.txtBoxall = tk.Text(self.allTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr1.set)
self.scrlr1.config(command = self.txtBoxall.yview)

#Create another sub-frame containing textbox and scrollbar for
the Violating files display
self.viTxtf = tk.Frame(self.mainWindow, width=699, height=164)
self.scrlr2 = tk.Scrollbar(self.viTxtf)
self. txtBoxvi = tk.Text(self.viTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr2.set)
self.scrlr2.config(command = self.txtBoxvi.yview)

#Create another sub-frame to contain the controls
self.ctrlFrame = tk.Frame(self.mainWindow, width=699,
height=72)
self.labDir = tk.Label(self.ctrlFrame, text="Dir:")
self.entDir = tk.Entry(self.ctrlFrame)
self.labChar = tk.Label(self.ctrlFrame, text="Char. Limit:")
self.entChar = tk.Entry(self.ctrlFrame)
self.btFind = tk.Button(self.ctrlFrame, text="Scan", command =
self.fillboxes)
self.btExit = tk.Button(self.ctrlFrame, text="Exit", command =
self.quitEvent)


#Use tkinter's grid geometry manager to allign and display the
GUI
self.mainWindow.grid()
#Frist allign the 3 main frames
self.labAll.grid(row=0)
self.allTxtf.grid(row=1)
self.labVi.grid(row=2)
self.viTxtf.grid(row=3)
self.ctrlFrame.grid(row=4)
#Now allign the content of allTxtf
self.txtBoxall.grid(row=0, column=0)
self.scrlr1.grid(row=0, column=1)
#Now allign the content for viTxtf
self.txtBoxvi.grid(row=0, column=0)
self.scrlr2.grid(row=0, column=1)
#Now allign the content for ctrlFrame
self.labDir.grid(row=0, column=0, sticky=tk.E)
self.entDir.grid(row=0, column=1)
self.labChar.grid(row=0, column=2, sticky=tk.E)
self.entChar.grid(row=0, column=3)
self.btFind.grid(row=0, column=4)
self.btExit.grid(row=0,column=5)

def findallfiles(self, base):
pass

def fillboxes(self):
pass

def quitEvent(self):
raise SystemExit

app = Theapp()
app.mainWindow.mainloop()

##End Code###

I have only posted the code relevant to the GUI.

TIA
Adam

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


Re: convert many excel files to pdf in batch

2007-02-28 Thread Adam
1. Get PDFCreator
2. Install
3. Set as default printer
4. Have all excel files in same folder
5. Select all excel files
6. Right click
7. Select Print
8. Save Each PDF to a location
9. ???
10. Profit

Never done it with Adobe Writer. I'm a cheapskate.

Regards,
Adam

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


Re: New to Tkinter GUI building

2007-02-28 Thread Adam
On Feb 28, 9:13 pm, Adonis Vargas <[EMAIL PROTECTED]>
wrote:
> Adam wrote:
>
> 
>
> > I think my main questions are:
> > 1. How can I get the Window to be sized the way I want it?
> > 2. How can I get the Scrollbars to fill the side of the text box
> > instead of being small? (like .pack(fill= tk.Y)
>
> 
>
> > I have only posted the code relevant to the GUI.
>
> > TIA
> > Adam
>
> To size the window use Tk's geometry method
>
>  self.top.geometry("%dx%d%+d%+d" % (800, 600, 0, 0)) # (width,
> height, x, y)
>
> For the scrollbar to fill vertically, use the sticky grid option.
>
>  self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
>
> Hope this helps.
>
> Adonis

Can't test now as its late in th UK and I'm going to bed. Looks good
though.
So remove the size from the frames etc and use the geometry method
instead? Then use grid to "pack" them for want of a better word?

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


Re: New to Tkinter GUI building

2007-03-01 Thread Adam
Ok the window has resized but the elements inside are still like they
were, so they are going off the edge on the window. How can I get
these to resize? I have put sizes on the frames they are in. Sorry to
keep asking but I'm flying blind here, I have checked the python site
and the intro to tkinter which are both usually good for this kinda
thing.

#CODE#

#file/path finder
#indentation value 4
import os,glob
import Tkinter as tk


# Class to create the Application and UI
class Theapp:
def __init__(self):
# Create GUI parts. Will allign later with grid
self.top = tk.Tk()
self.top.geometry("%dx%d%+d%+d" % (700, 400, 0, 0)) #
(width,height, x, y)
self.mainWindow = tk.Frame(self.top)#width=700, height=400)
self.labAll = tk.Label(self.mainWindow, text="All Files/
Folders:")
self.labVi = tk.Label(self.mainWindow, text="Violating Files/
Folders:")

#Create a sub-frame containing textbox and scrollbar for All
files scanned display
self.allTxtf = tk.Frame(self.mainWindow, width=690,
height=164)
self.scrlr1 = tk.Scrollbar(self.allTxtf)
self.txtBoxall = tk.Text(self.allTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr1.set)
self.scrlr1.config(command = self.txtBoxall.yview)

#Create another sub-frame containing textbox and scrollbar for
the Violating files display
self.viTxtf = tk.Frame(self.mainWindow, width=690, height=164)
self.scrlr2 = tk.Scrollbar(self.viTxtf)
self. txtBoxvi = tk.Text(self.viTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr2.set)
self.scrlr2.config(command = self.txtBoxvi.yview)

#Create another sub-frame to contain the controls
self.ctrlFrame = tk.Frame(self.mainWindow, width=690,
height=72)
self.labDir = tk.Label(self.ctrlFrame, text="Dir:")
self.entDir = tk.Entry(self.ctrlFrame)
self.labChar = tk.Label(self.ctrlFrame, text="Char. Limit:")
self.entChar = tk.Entry(self.ctrlFrame, textvariable="254")
self.btFind = tk.Button(self.ctrlFrame, text="Scan", command =
self.fillboxes)
self.btExit = tk.Button(self.ctrlFrame, text="Exit", command =
self.quitEvent)


#Use tkinter's grid geometry manager to allign and display the
GUI
self.mainWindow.grid()
#Frist allign the 3 main frames
self.labAll.grid(row=0)
self.allTxtf.grid(row=1)
self.labVi.grid(row=2)
self.viTxtf.grid(row=3)
self.ctrlFrame.grid(row=4)
#Now allign the content of allTxtf
self.txtBoxall.grid(row=0, column=0)
self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
#Now allign the content for viTxtf
self.txtBoxvi.grid(row=0, column=0)
self.scrlr2.grid(row=0, column=1, sticky=tk.N + tk.S)
#Now allign the content for ctrlFrame
self.labDir.grid(row=0, column=0, sticky=tk.E)
self.entDir.grid(row=0, column=1)
self.labChar.grid(row=0, column=2, sticky=tk.E)
self.entChar.grid(row=0, column=3)
self.btFind.grid(row=0, column=4)
self.btExit.grid(row=0,column=5)

def findallfiles(self, base):
Pass

def fillboxes(self):
Pass

def quitEvent(self):
    raise SystemExit


app = Theapp()
app.mainWindow.mainloop()

#END#

Regards,
Adam

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


python - stealth window

2007-11-07 Thread Adam
Hello,

I want create Windows console window in stealth with Python script. I tried
search on internet but I do not find anything. I want something like this
just it is in C++:

HWND stealth; /*creating stealth (window is not visible)*/
AllocConsole();
   stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);

So I start my script and that is will be run in the background and I can
trick with "hotkeys" in WINAMP. I do not worry for a new one window. :-) I
hope you understand me because my english is not perfect.

Regards,

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

ILOG Server integration

2006-04-27 Thread adam

Does anybody have experiences of Python and ILOG Server (distribution
framework) integration?
I need to access to a server application "exposed" through ILOG Server.

Thanks
Vieri

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


call an exturnal program in python

2008-11-21 Thread Adam
I am trying to run an external program in my code using 
os.system('exename -exearg') but the exe has an "&" in it so windows thinks 
it's two commands any way around this?


Adam 


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


Mangle function name with decorator?

2009-03-17 Thread Adam
I am using Python 2.5, and I would like to write a decorator (or using
some other elegant, declarative approach) to mangle the name of
function in a class.  I would like to be able to have two methods
declared with the same name, but one of them will have a decorator (or
whatever) that will change the name of one of them.

Example:

class A(object):
def __init__(self, method, usebar = False):
self.method = method
self.usebar = usebar

def __call__(self):
if self.usebar == True:
mangled_name = "_bar_" + self.method
if hasattr(self, mangled_name):
return getattr(self, mangled_name)()
else:
return getattr(self, self.method)()
else:
if hasattr(self, self.method):
return getattr(self, self.method)()
else:
raise NotImplementedError

@bar
def foo(self):
print "in _bar_foo"

def foo(self):
print "in foo"

Desired output:
>>>y = A("foo", True)
>>>y()
in _bar_foo
>>>z = A("foo")
>>>z()
in foo


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


Re: Mangle function name with decorator?

2009-03-17 Thread Adam
Thanks, Andrew.  I'm trying to accomplish something with a
metaprogramming flavor, where, for the convenience of the programmer
and the clarity of code, I'd like to have a decorator or some other
mechanism do twiddling behind the scenes to make a class do something
it wouldn't normally do.

Here's a less-obfuscated exmaple:  I want to build a framework for
creating MVC web applications in Python (I know, I know, there's
already 2^1bazillion of them) where a controller class can have
methods that respond to the same action but for different HTTP verbs:

class foo_controller(Controller):
@GET
def new(self):
# Display the form to create a new foo

@POST
def new(self):
# Receive a form post with new foo data in it

The Controller class will do all of the work behind the scenes to
makes sure that the correct method is called at run-time, but for the
sake of the programmer, I'd like to supply a clear, friendly syntax
like this.  Without a little metaprogramming magic, last-in-wins, and
only the second version of foo will end up in the class, so I'd like
to mangle the names to something that will result in a unique
attribute name and that the Controller class can work with behind the
scenes to do the right thing at run time.

So, Python experts, am I completely barking up the wrong tree here?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mangle function name with decorator?

2009-03-18 Thread Adam
On Mar 17, 1:49 pm, Aaron Brady  wrote:

> You would need a unique attribute to look for on values in the
> dictionary, which means you'd need to detect what functions you are
> renaming; possibly by using a decorator to mark them.  (Untested:)
>
> class X( metaclass= M ):
>   @mark( 'A' )
>   def foo( ... ).
>
> class M( type ):
>   def __new__( cls, name, bases, namespace ):
>     for k, v in namespace.items():
>       if v.tag== 'mark-A':
>         namespace[ k ]= modification( v )
> or in your case:
>         del namespace[ k ]
>         namespace[ k_mod ]= v.original
>
> possibly also setting func_name as well.
>     return type( name, bases, namespace )

I tried this, but unfortunately, it still doesn't allow me to have two
methods that initially have the same name, because the namespace
dictionary that the metaclass gets only has one one entry, the last
one in.  So, if I try code like this:

def get_only(action):
setattr(action, "get_only", True)

return action

class ControllerMetaclass(type):
def __new__(cls, name, bases, namespace):
print str(namespace)
for k, v in namespace.items():
if hasattr(v, "get_only"):
new_name = "_get_" + k
print "new_name is " + new_name
del namespace[k]
namespace[new_name] = v
v.__name__ = new_name
return type(name, bases, namespace)

class Controller(object):
def __call__(self):
if (self.method != None):
get_mangled_name = "_" + self.method + "_" + self.action
if hasattr(self, get_mangled_name):
method = getattr(self, get_mangled_name)
return method()
else:
if hasattr(self, self.action):
return getattr(self, self.action)()
else:
raise NotImplementedError
else:
if hasattr(self, self.action):
return getattr(self, self.action)()
else:
raise NotImplementedError

class foo_controller(Controller):
__metaclass__= ControllerMetaclass
def __init__(self, action, method = None):
self.action = action
self.method = method


def foo(self):
print "in foo()"

@get_only
def foo(self):
print "in get_only foo()"

def bar(self):
print "in bar()"


a = foo_controller("foo", "get")
a()

b = foo_controller("foo")
print dir(b)
b()

c = foo_controller("bar","get")
c()

The first definition of foo (the one that is not decorated) is over-
written by the second one, and the metaclass never sees it.  So, I
think that I understand what you said about storing the functions in a
hashtable.  That makes sense, as I can keep a reference to the
function even if ti gets over-written in the class main namespace
dictionary.  However, I'm not entirely sure about how to do that with
decorators.  Wouldn't the decorator function have to be bound to a
context to keep a hastable between calls?  I can't us a bound method
as a decorator, can I?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mangle function name with decorator?

2009-03-18 Thread Adam
On Mar 18, 10:33 am, "J. Cliff Dyer"  wrote:
> You might be interested in redefining __getattribute__(self, attr) on
> your class.  This could operate in conjunction with the hash tables
> (dictionaries) mentioned by andrew cooke.  i.e. (untested code):
>
> class C(object):
>     def __init__(self):
>         self._get_table = {}
>         self._post_table = {}
>
>     def __getattribute__(self, x):
>         if self.method=='GET':
>             return object.__getattribute__(self, _get_table)[x]
>         elif self.method=='POST':
>             return object.__getattribute__(self, _post_table)[x]
>         else:
>             raise AttributeError
>     @GET
>     def foo(x):
>         return "Got", x
>     @POST
>     def foo(x)
>         return "Posted to", x
>
> This is definitely not functional code, but might get you in the right
> direction on __getattribute__.  __getattr__ might also work for you.  I
> haven't worked too much with these corners of python.
>
> Cheers,
> Cliff

Hey, Cliff.  Thanks for sharing this idea.  Unfortunately, providing a
way to actually call the method with the mangled name is relatively
easy, and there are options there.  The real issue, to me, seems to be
finding a way to prevent Python from eating all but the last version
of a function definition in a class.  While decorators are a elegant
and unintrusive approach, I don't believe that there is any way for a
decorator to collection information in a data structure and then
provide that data back to the class instance or the class's metaclass.

I'm beginning to think that I am trying to get the square peg of
Python to fit into the round hole of a .NET idiom.  I am trying to
borrow what I think is a really elegant and useful idiom from ASP.NET
MVC.  Specifically, in an ASP.NET MVC Controller class, I can have two
methods with the same name that are called for different HTTP Verbs by
applying an Attribute:

public ActionResult Payment() {
ViewData["Title"] = "Payment Information";
ViewData["submit_text"] = "Next >";

return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Payment(FormCollection form) {

return RedirectToAction("Legal");
}

Right?  The first Payment method is called when the Payment page is
rendered.  The second is called when the form that it contains is
submitted.  I find it to be readable, elegant and it does not intrude
into the actual logic of the method itself.  The alternatives that I
can readily identify are less-than-optimal.  For instance, if could
just have an if statement inside the body of the method that branches
on the HTTP verb:

def Payment(self):
if self.request.verb == 'GET':
# Do stuff for GET
elif self.request.verb == 'POST':
# So stuff for POST

Yes, it would work, but it is ugly and requires me to mix in the same
function the behaviors for two very separate things.

Or, I could do something like this:

def GET_Payment(self):
# Do stuff for GET

def POST_Payment(self):
# Do stuff for POST

This is trivially-easy to implement (in this case, a metaclass can
very easily manipulate the namespace), but it makes the source code
less appealing and just feels crufty and hacky.  It also makes it
difficult to deal elegantly with having one method respond to more
than verb like I could if I could write:

@GET
@POST
def foo(self):
# Do stuff for page foo, if it is GET or POST; PUT and DELETE not
allowed!


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


Re: Mangle function name with decorator?

2009-03-18 Thread Adam
On Mar 18, 11:11 am, "R. David Murray"  wrote:
> I don't have any wisdom on the metaclass/decorator stuff, but what
> about slightly reformulating the interface?  Instead of having the
> programmer type, eg:
>
>     @GET
>     def foo(self): pass
>
>     @POST
>     def foo(self): pass
>
> have them type:
>
>     def GET_foo(self): pass
>     def POST_foo(self): pass
>
> It's even one less character of typing (the  :)
>
> --
> R. David Murray          http://www.bitdance.com

David, would you believe that I just posted about this very idea,  It
doesn't seem to have shown up yet, though.  This idea works from the
perspective of being trivially easy to implement.  I can easily write
a metaclass that looks in the namespace for methods with names that
start with GET_or POST_, or I can override __getattribute__ to do the
look up that way.  However, there are a couple of weaknesses that I
see with this approach.

First, from a purely aesthetic point of view, prepending the desired
verb to the method name just looks a bit ugly.  Also, it makes it
difficult to deal elegantly with avoiding duplicating code when one
piece of logic should dealing with more than one verb.  So, if I want
to have one method that works for GET and POST, I can do this:

def GET_foo(self):
# Do stuff for GET

def POST_foo(self):
return self.GET_foo()

but then I feel like I am cluttering my controller code with unneeded
functions when writing
@GET
@POST
def foo(self):
   # Blah blah blah

would be so much neater.

Or, I could allow method signatures like:
def GET_POST_foo(self):
   # Blah, blah, blah

But now my code to parse and manipulate or do lookups on methods names
is much more complicated.  Also, it introduces difficult ambiguities
in the case that an action of the controller has the same name as an
HTTP Verb.  These ambiguities can be coded around, but doing so makes
the code more-and-more crufty and prone to breakage.  I don't want to
build too much of a Rube Goldberg machine here, right?  What I really
want to do is use Python's metaprogamming facilities to provide an
elegant solution to a problem.  Unfortunately, I really don't think
that it is going to work out in any way that is really satisfying.
--
http://mail.python.org/mailman/listinfo/python-list


How to set proxy for a python script to run

2008-04-17 Thread Adam
Hi, everyone, I am using /usr/share/system-config-language/
language_gui.py in Python.
For some reason I have to bypass the firewall using a proxy. I read
the urllib reference and set http_proxy="my proxy". But it didn't
work. Is there anyway that we can set the proxy?
-- 
http://mail.python.org/mailman/listinfo/python-list


How to set proxy for a python script to run

2008-04-17 Thread Adam
Hi, I am using a script written in Python. For some reasons I should
pass the fireware by proxy setting. But it seems not work when I set
the 'http_proxy' 'ftp_proxy' environment variable.
I also expored 'HTTP_PROXY' 'FTP_PROXY', but the problem remained.
How can I set proxy for it to run the script?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can httplib.HTTPConnection use proxy?

2006-03-16 Thread adam
>>> import httplib
>>> h = httplib.HTTPConnection("www.google.ca")
>>> h.connect()
Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\lib\httplib.py", line 627, in connect
raise socket.error, msg
error: (10061, 'Connection refused')
>>> h2 = httplib.HTTPConnection("my.proxy.host", "my.proxy.port")
>>> h2.connect()
>>> h2.request("GET", "http://www.google.ca";)
>>> resp = h2.getresponse()
>>> page = resp.read()

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


Re: Content Management System

2006-03-29 Thread Adam
On Wed, 29 Mar 2006 16:32:39 GMT, Adrienne Boswell wrote:

>Gazing into my crystal ball I observed "Water Cooler v2" 
><[EMAIL PROTECTED]> writing in news:1143627824.174540.13710
>@z34g2000cwc.googlegroups.com:
>
>> I know what it is, and yet the knowledge of what a CMS is, is so vague
>> that I find myself asking this question every now and then. I've
>> googled and read the resources too. However, the knowledge is still not
>> clear. It is so vague.
>> 
>> 
>
>For me, it was a way to give my client (local parish) some things:
>1. An easy way for them to make _content_ changes to their website, 
>without getting into the nuts and bolts and potentially creating havoc.
>2. A way to make the site searchable for the user.
>3. A way from keeping them from publishing Word documents as HTML - urgh!
>4. A way to have content changes immediate, and not have to wait for 24 
>hours before their current hosting company downloads content (in Word, 
>with no navigation).
>
>I rolled my own in ASP/Access, not very complicated because I didn't need 
>anything complicated.

Try taking a look at Joomla:

http://www.joomla.org/

I generally hand code PHP sites, but occasionally use a CMS. Of all
the ones I tested, Joomla seemed (to me) to be the most flexible.

If you install the JCE (WYSIWYG) editor, it actually has a "paste from
Word" function that tries to strip out as much MX cr*p as it can - but
it's a tall order!

I've [even] used Joomla for pretty simple non-"blog" sites simply for
the remote admin and the search functions. It really is best suited
for the more "newsy" community sites. It's definitely worth a look at,
IMHO.

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


which scipy binary for Win32

2011-01-25 Thread Adam
Am looking at 
http://sourceforge.net/projects/scipy/files/scipy/0.8.0/
and I wonder which is the binary to install on WinXP ? 
As pointed to by this page, http://www.scipy.org/Download 

All I can see on that sourceforge page are the huge 
python2.6 and python2.7 Powerpacks, at 43megs or so 
each. The scipy-0.8.0.zip seems to require compilation. 


FYI: I'm installing Python 2.7, so have uninstalled all 
Python2.5 and Python2.6, including older numpy, scipy and 
matplotlib. 

Presently, prior to installation, I have; 
python-2.7.1.msi  (15.628 meg)
numpy-1.5.1-win32-superpack-python2.7.exe  (5.354 meg)
matplotlib-1.0.1.win32-py2.7.exe  (8.105 meg) 

Does the scipy 2.7 Powerpack include numpy anyway ? 

Any recommendations or pointers appreciated. Thanks. 


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


Re: Compiling 64 bit python on a mac - cannot compute sizeof (int)

2009-07-03 Thread Adam
On Jul 3, 2:18 pm, Mark Dickinson  wrote:
> On Jul 3, 5:30 pm, Keflavich  wrote:
>
> > I'm trying to compile a 64 bit version of python 2.6.2 on my mac (OS X
> > 10.5.7), and am running into a problem during the configure stage.
>
> > I configure with:
> > ./configure --enable-framework=/Library/Frameworks --enable-
> > universalsdk MACOSX_DEPLOYMENT_TARGET=10.5 --with-universal-archs=all -
> > with-readline-dir=/usr/local
>
> > because I want 64 and 32 bit, and I needed to install a 64 bit
> > readline as a prerequisite.
>
> > configure fails at:
> > checking size of int... configure: error: cannot compute sizeof (int)
>
> I confess that I don't fully understand the intricacies of the various
> OS X autoconf options, but I think the problem is that the --enable-
> universalsdk option takes a directory.  If that directory isn't
> given, it appears to default to /Developer/SDKs/MacOSX10.4u.sdk (at
> least on my OS X 10.5.7 machine), which would likely conflict with
> your MACOSX_DEPLOYMENT_TARGET=10.5 setting.
>
> Try either changing MACOSX_DEPLOYMENT_TARGET to 10.4, or using --
> enable-universalsdk=/Developer/SDKs/MacOSX10.5.sdk  (or whatever the
> appropriate directory is on your system).  For some reason, I think
> using --enable-universalsdk=/ also works on my system.  If none of
> that helps, you might try asking this question over on the pythonmac-
> sig mailing list. (http://mail.python.org/mailman/listinfo/pythonmac-
> sig)
>
> Mark

Thanks.  I also determined after the fact that universalsdk was the
problem, but I didn't know how to fix it.  Unfortunately, it turns out
what you identified was a transcription error on my part - I had been
using --enable-universalsdk instead of --enable-universalsdk=/.
Thanks for the help, I appreciate it!

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


Re: Entry Level Python Jobs

2009-09-02 Thread Adam
On Sep 2, 11:31 am, JonathanB  wrote:
> For the hiring managers, if the job post said
> "CS Major" in the requirements, would you consider a liberal arts
> major at all?

I got my English Writing degree in 1990, and I have been a software
engineer ever since. Landing the first job was very difficult, but it
gave me the foundation of experience that allowed me to circumvent the
"CS-degree or equivalent" requirement on every job that I have had
since. If you do choose to pursue software development as a career,
you'll be shocked at how many of your fellow liberal arts degree
holders are doing the same.

It will be a hard road. You will have to overcome significant
obstacles. You will do boring, tedious work. You will find out what it
really means to pay one's dues. You will also, perchance, succeed and
find happiness in a fulfilling career.

I think that Python is an outstanding foundation for learning
programming, but I would advise you to branch out as quickly as
possible. I imagine that saying so won't endear me to anyone here, but
in good conscience, I have to recommend C# and the .NET framework; it
has lead me to continual and well-paying employment for many, many
years now. Also, put together an on-line portfolio of code, preferably
composed of complete and useful programs. Actually seeing well-
written, well-documented code can go a long way towards getting you in
the door for an interview.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Entry Level Python Jobs

2009-09-02 Thread Adam
On Sep 2, 12:52 pm, JonathanB  wrote:
>  Any other tips?

I'm probably going to come off as very old school, but give yourself a
good and thorough education in data structures and algorithms. You
might never be called on to actually code a quick sort, merge sort,
heap sort, doubly-linked list or trie, but knowing what they are and
why they are important will fundamentally shape how you approach all
software problem solving.

There are a lot of good data structures and algorithms books that use
C, so that'd be a good approach to also adding a very important
language to your toolbelt.
-- 
http://mail.python.org/mailman/listinfo/python-list


ValueError: I/O operation on closed file. with python3

2013-06-11 Thread Adam Mercer
Hi

I'm trying to update one of my scripts so that it runs under python2
and python3, but I'm running into an issue that the following example
illustrates:

$ cat test.py
try:
  # python-2.x
  from urllib2 import urlopen
  from ConfigParser import ConfigParser
except ImportError:
  # python-3.x
  from urllib.request import urlopen
  from configparser import ConfigParser

server='http://www.lsc-group.phys.uwm.edu/~ram/files'

fp = urlopen('%s/latest.ini' % server).fp
cp = ConfigParser()
cp.readfp(fp)
print(cp.get('version', '10.8'))
$

This works as expected when using python2:

$ python2.7 test.py
5.2.10
$

but when using python3 I receive the following error:

$ python3.3 test.py
Traceback (most recent call last):
  File "test.py", line 14, in 
cp.readfp(fp)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/configparser.py",
line 753, in readfp
self.read_file(fp, source=filename)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/configparser.py",
line 708, in read_file
self._read(f, source)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/configparser.py",
line 1010, in _read
for lineno, line in enumerate(fp, start=1):
ValueError: I/O operation on closed file.
$

Is there a way to get this working in both python2 and python3?

This is a small script and I'm starting to have some users wanting to
use python3 and others sticking to python2 so I'd like to accommodate
them both if possible.

Cheers

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


Re: ValueError: I/O operation on closed file. with python3

2013-06-12 Thread Adam Mercer
On Wed, Jun 12, 2013 at 2:26 AM, Peter Otten <__pete...@web.de> wrote:

> Applying these findings to your script:
>
> from contextlib import contextmanager
> try:
>   # python-2.x
>   from urllib2 import urlopen
>   from ConfigParser import ConfigParser
>
>   @contextmanager
>   def my_urlopen(url):
>   yield urlopen(url).fp
>
> except ImportError:
>   # python-3.x
>   from urllib.request import urlopen
>   from configparser import ConfigParser
>   import io
>
>   @contextmanager
>   def my_urlopen(url):
>   resp = urlopen(url)
>   yield io.TextIOWrapper(resp.fp)
>
> server='http://www.lsc-group.phys.uwm.edu/~ram/files'
>
> cp = ConfigParser()
> with my_urlopen('%s/latest.ini' % server) as fp:
> cp.readfp(fp)
>
> print(cp.get('version', '10.8'))
>
> I've run it with 2.6, 2.7, 3.2, and 3.3.

Thanks that's very helpful, I hadn't realised that .readfp() had been
deprecated.

Cheers

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


Re: What is the semantics meaning of 'object'?

2013-06-23 Thread Adam Jiang
> * property only works in "new-style" classes that inherit from object;
> 
> * likewise for super;

Another question raised here is that what is the proper way to refer
to parent class? For example,

class A(object):
def __init__(self, arg):
print "A"

class B(A):
def __init__(self, arg):
super(B, self).__init__(arg)

Is this correct? As the result, whenever you wanted to refer to a
method in parent class, super() functions has to be called. This seems
inefficient.

How to refer to a field defined in parent class?

Thanks,
/Adam

>On Sun, Jun 23, 2013 at 03:20:02AM +, Steven D'Aprano wrote:
> On Sat, 22 Jun 2013 19:58:38 -0700, Adam wrote:
> 
> > class FooBar(object):
> > def __init__(self):
> > ...
> > 
> > Inheritance usually takes a class name to indicate which class is the
> > 'parent' class. However, in the previous example, from a django book,
> > the class actually takes an 'object' like parameter, doesn't it? What is
> > the semantics meaning of such kind of notation?
> 
> It's not merely notation, "object" is the name of a class. If you type it 
> (without quotes) at the interactive interpreter, you will see it is a 
> built-in class:
> 
> py> object
> 
> 
> 
> In Python 3, the use of object as base class is optional, but in Python 2 
> there is a subtle difference between classes that inherit from object and 
> those that don't. The reason for this difference is buried in the mists 
> of time, going back to Python 2.2. If you are interested, google on 
> "Python unifying types and classes":
> 
> https://duckduckgo.com/html/?q=Python+unifying+types+and+classes
> 
> 
> As a general rule, unless you actually want "old-style class" behaviour, 
> you should always inherit from object (or some other built-in type) in 
> Python 2. In Python 3, it doesn't matter.
> 
> The differences include:
> 
> * property only works in "new-style" classes that inherit from object;
> 
> * likewise for super;
> 
> * multiple inheritance with old-style classes can be buggy;
> 
> * new-style classes may be slightly faster in general;
> 
> * on the down side, automatic delegation of special double-underscore 
> methods like __getitem__ and __str__ doesn't work with new-style classes.
> 
> 
> If none of this means anything to you, be glad, and just inherit from 
> object or some other built-in type in all your classes, and all will be 
> good.
> 
> 
> 
> 
> -- 
> Steven
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Sending USB commands with Python

2012-08-28 Thread Adam W.
So I'm trying to get as low level as I can with my Dymo label printer, and this 
method described the PDF 
http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdf seems to 
be it.

I'm unfamiliar with dealing with the USB interface and would greatly appreciate 
it if someone could tell me how to send and receive these commands with Python. 
 Perhaps if you were feeling generous and wanted to write a bit of sample code, 
sending the "Get Printer Status" command and receiving the response (page 17 of 
the PDF) would be perfect to get me on my way.

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


Re: Sending USB commands with Python

2012-08-29 Thread Adam W.
On Wednesday, August 29, 2012 2:45:17 AM UTC-4, Tim Roberts wrote:
> Which operating system are you using?  If you are on Windows, then the
> 
> operating system has already loaded a printer driver for this device. 
> 
> 
> The libusb or libusbx libraries can be used to talk to USB devices.  There
> 
> is a Python binding.  On Windows, you still need to have a driver, but the
> 
> libusbx instructions can help you find an install one.
> 

I am on Windows and have installed a driver using libusb-win32.  Using 
http://pyusb.sourceforge.net/docs/1.0/tutorial.html as a template, this is my 
code so far:

import usb.core
import usb.util

dev = usb.core.find(idVendor=0x0922, idProduct=0x0021)

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
interface_number = cfg[(0,0)].bInterfaceNumber
alternate_settting = usb.control.get_interface(dev,interface_number)
intf = usb.util.find_descriptor(
cfg, bInterfaceNumber = interface_number,
bAlternateSetting = 0
)

ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT
)

assert ep is not None


I had to manually set bAlternateSetting to 0 for it to run and add dev to 
usb.control.get_interface(dev,interface_number).

Trying to do the status thing mentioned before, in the interpreter I did:

>>> ep.write('A')
2

And the manual says 2 is not a valid option... So something isn't adding up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending USB commands with Python

2012-08-29 Thread Adam W.
On Wednesday, August 29, 2012 4:09:49 PM UTC-4, Dennis Lee Bieber wrote:
>
>   Don't the commands require an  character? "\x1BA" (or
>"\x1B\x41")
> 
>   OTOH, if the  is issued behind the scenes,

I'm not sure which esc char it is asking for, I don't think libusb is providing 
its own, and it seems like the one you suggested isn't what it wants either..

>  ... and you do not need to issue some sort of read()
> the "2" you are seeing is the "number of bytes written";
> 
> you need to issue a read request to retrieve the returned printer
> 
> status.
> 

You are correct about the 2 being the number of bytes written.  However when I 
issue a read command I get:

>>> ep.write('\x1BA')
4
>>> ep.read(1)
Traceback (most recent call last):
  File "", line 1, in 
ep.read(1)
  File "C:\Python32\lib\site-packages\usb\core.py", line 301, in read
return self.device.read(self.bEndpointAddress, size, self.interface, 
timeout)
  File "C:\Python32\lib\site-packages\usb\core.py", line 654, in read
self.__get_timeout(timeout)
  File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 483, in 
bulk_read
timeout)
  File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 568, in 
__read
timeout
  File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 384, in 
_check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_setup_async] invalid 
endpoint 0x02\n'

Avoiding the read command all together I should be able to write " E" and 
have it feed some paper, which it is not doing, so obviously there is more to 
uncover.  That said I feel this endeavor has evolved and is no longer pertinent 
to the Python group so I will let you guys off the hook on this (although 
responses/suggestions are still welcome).

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


Re: Sending USB commands with Python

2012-08-29 Thread Adam W.
On Wednesday, August 29, 2012 6:56:16 PM UTC-4, Dennis Lee Bieber wrote:
>
>   BUT you do give a possible clue. Is the OP using a 3.x Python where
> 
> strings are Unicode -- in which case the above may need to be explicitly
> 
> declared as a "byte string" rather than text (unicode) string.
> 

Huzzah!  I am indeed using 3.x, and slapping on an .encode('utf-8') made my 
printer try to spit paper at me! Progress.

Also, astute observation about the endpoint needing to be an input, with the 
following modification I get:

>>> ep.write('\x1BA'.encode('utf-8'))
2
>>> ep = usb.util.find_descriptor(
intf,
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN
)
>>> ep.read(1)
array('B', [163])
>>> 

Anyone want to venture a guess on how I should interpret that?  It seems the 
[163] is the byte data the manual is talking about, but why is there a 'B' 
there?  If I put paper in it and try again I get: array('B', [3])

Thanks for all your help guys, just about ready to stared coding the fun part!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending USB commands with Python

2012-08-29 Thread Adam W.
On Wednesday, August 29, 2012 10:07:54 PM UTC-4, Dennis Lee Bieber wrote:
> On Wed, 29 Aug 2012 16:45:10 -0700 (PDT), "Adam W."
>
>   I'm a tad curious if using the notation
> 
> 
> 
>   b'\x1bA'
> 
> 
> 
> without the .encode() would work.
> 
> 
> 
>   My concern is that you may encounter some "string" of data for
> 
> printing which the .encode() ends up /changing/ (don't UTF-8 strings use
> 
> a high-bit to signal a multi-byte encoding of what had been a single
> 
> character?). A pure byte string shouldn't have that problem.
> 

Your notation does work, and I was just coming around to reevaluating the use 
of the encode because I am getting really odd results when trying to print 
lines.

For example I set the byte length to 10 and sent this 500 times or so expecting 
to get a solid black bar:
ep.write('\x16FF'.encode('utf-8'))

But what I got was a weird stripped pattern...  I feel like a lot of my 
commands are working by chance, I can't explain to myself why the A in \x1bA 
isn't being treated as part of the hex.  This stuff always confuses me.


> 
> > >>> ep = usb.util.find_descriptor(
> 
> > intf,
> 
> > custom_match = \
> 
> > lambda e: \
> 
> > usb.util.endpoint_direction(e.bEndpointAddress) == \
> 
> > usb.util.ENDPOINT_IN
> 
> > )
> 
> 
> 
>   Seems tedious to keep swapping -- does USB support bidirectional
> 
> connections?
> 

I assigned the input to ep2 to resolve the switching issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending USB commands with Python

2012-08-30 Thread Adam W.
On Thursday, August 30, 2012 12:55:14 AM UTC-4, Dennis Lee Bieber wrote:
>
>   How many bytes did it claim to send?
> 
11, which is what I expected.  But I changed the byte value to 16 (because I 
was having trouble getting single digit hex values working in the command) and 
sent this command:
>>> for x in range(0,500):

ep.write(b'\x16\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')

it respond with 500 17's and prints a black bar!  So it looks like whatever 
concern you had with using encode was coming to fruition.

> 
>   That's the easy one -- \x in a string introduces an 8-bit byte value
> 
> -- so only two hex digits well be read. The "A" is interpreted as
> 
> regular text.

Interesting, so what if I only wanted to send 4bits as a hex value?  Also can I 
somehow throw in some binary alongside of hex?  At some point in my program I'm 
going to need to send some commands preferably in hex along with the binary 
image data.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Mark Adam
On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
 wrote:
> There are many situations where a little bit of attribute access magic is a
> good thing. However, operations that involve the underlying OS and that are
> prone to raising exceptions even in bug free code should not be performed
> implicitly like this. I find the following a little cryptic:
> try:
> f.pos = 256
> except IOError:
> print('Unseekable file')

Well it might be that the coupling between the python interpreter and
the operating system should be more direct and there should be a
special exception class that bypasses the normal overhead in the
CPython implementation so that error can be caught in the code without
breaking syntax.  But I don't think I'm ready to argue that point

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


Re: Are ABCs an anti-pattern?

2012-10-02 Thread Mark Adam
On Tue, Oct 2, 2012 at 9:23 AM, Demian Brecht wrote:

> I don't use them anymore, but I'm curious about others opinions on this
> list...
>

Interesting question.  I think they haven't been useful for representing
the real world as everyone hoped, but are pretty good for organizing
structures within the Python universe (like "object "collections" -->
{'list','set','dict'...}, for example).

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


Re: Emulating C++ namespaces with ChainMap and metaclass trickery

2012-10-03 Thread Mark Adam
On Wed, Oct 3, 2012 at 1:26 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> C++ namespaces are useful for encapsulating related objects within a
> single file, subdividing the global namespace without using classes.
> Python has modules, but they come in separate files.
>
> Using Python 3.3's ChainMap type, and some metaclass trickery, I abuse
> the class keyword to (almost) emulate C++ namespaces:
>

Very interesting.  I like the idea of continuing the namespace meme.

My idea of using the builtins (in the prior list thread of "namespaces and
modules"), is that if we overhaul the builtins, a unified data model could
emerge to incorporate whatever ideas one may have for namespaces (i.e.
"enclosures with a name").

My idea was to introduce the compound data type (using a ":" colon to
separate two sides), whereby one associates a (*hashable*) "name"  with an
object ("meals":{"breakfast","lunch","dinner"}) .  This has the extra
advantage of killing two warts in Python with one stone:  {} now is the
empty set literal like people are taught, and a set of compounds makes a
dictionary (dict now has set operations available), something which, in
theory, should simply CPython implementation AND the python environment/API.

"expose name" put the dictionary (or whatever type is decided for the rhs)
into the builtin/global namespace.

I have further thoughts, but that's all I have at the moment

markj
gothenburg, nebraska
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't run any script without it failing due to calling tkinter for no reason

2012-10-14 Thread Adam G
On Sunday, October 14, 2012 7:19:24 PM UTC-7, Benjamin Kaplan wrote:
> On Sun, Oct 14, 2012 at 6:47 PM,   wrote:
> 
> > Hello All,
> 
> >
> 
> >
> 
> > I'm running python 3.2 on Freebsd 9.0 Release and I must've screwed up my 
> > environment somehow, because now I can't run any script without it failing 
> > and throwing:
> 
> > ** IDLE can't import Tkinter.  Your Python may not be configured for Tk. **
> 
> >
> 
> > Yet none of my scripts use tkinter nor call that module. They're simple 
> > network scraping scripts. I use pydev and eclipse and must've fat fingered 
> > something that screwed up my python environment, but I haven't the 
> > slightest clue on how to fix it. I can run my scripts in idle no problem, 
> > but I've built them as command line apps. I've tried uninstalling python 3 
> > and reinstalling it to no avail. What did I do, and how can I fix it?
> 
> >
> 
> > Thanks,
> 
> > Adam
> 
> > --
> 
> 
> 
> IDLE uses Tkinter. If you don't have Tk installed, just run the
> 
> scripts from the terminal or pick a different IDE.



Hi Ben,


Your reply instantly triggered my aha moment and I figured it out. I had an 
import to idlelib in one of my modules dependencies from an eclipse 
auto-import. I feel foolish for not seeing it sooner. I use eclipse and pydev 
and use a module to do all the heavy network code for my front end command line 
scripts. In that module I used a function variable called host where eclipse, 
oh so helpfully, gave me the option of resolving an import I never asked for by 
automatically importing some module from idlelib. It was from idlelib import 
host as HOST or something to that effect. Damn eclipse does that to me from 
time to time and it happens so fast I don't even see what it does. Thanks for 
the reply and helping me see my erroneous ways.

Cheers,
Adam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a.index(float('nan')) fails

2012-10-27 Thread Mark Adam
On Thu, Oct 25, 2012 at 9:04 PM, Terry Reedy  wrote:
> On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote:
>
> a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> a
>>
>> [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>
> a.index(float('nan'))
>>
>> Traceback (most recent call last):
>>File "", line 1, in 
>> ValueError: list.index(x): x not in list
>>
>> That means, the function .index() cannot detect nan values.
>> It happens on both Python 2.6 and Python 3.1
>>
>> Is this a bug? Or I am not using .index() correctly?
>
>
> It is a consequence of the following, which some people (but not all)
> believe is mandated by the IEEE standard.
>
 nan = float('nan')
 nan is nan
> True

It should be noted, for the record, that "nan is nan" returning True
has nothing to do with the concept of numbers or the IEEE standard and
is purely a consequence that Python runs on hardware with memory
addresses and such.

 nan == nan
> False

Here, equality, IS about number and this is appropriate and conforms
to the IEEE standard.

 nanlist = [nan]
 nan in nanlist
> True
 nanlist.index(nan)
> 0

Here you just see an phenomenon with the python object/reference
model, which, being as it is, has nothing to do with numbers.  This is
an area which, potentially could be changed in Python without
violating the IEEE standard whatsoever.

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


Re: Paid Python work for 30mins - 1 hour

2012-11-19 Thread Mark Adam
On Mon, Nov 19, 2012 at 10:14 AM,   wrote:
> I have three scripts that I would like written, they are designed to do the 
> following:
>
> Backup.py – Zip a folder and store it on amazon S3 using BOTO with the date 
> and time as the folder name.
>
> Restore.py – Grab a file from S3 and download it and then unzip it in the 
> right location with two commandline parameters (1 = Get most recent, 2 = Get 
> specific file)
>
> Import.py – Check that I have done this correctly and add command line 
> parameter for changing the command
>
> This code is probably 50% completed already and if someone knows what they 
> are doing, could be completed in a very short time. It is really basic Python 
> code, I just dont know python myself.
>
> If you are interested get in touch!

You might consider putting your request on  elance.com or guru.com
where you can hire programmers for small projects like this.

Good luck,

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


Determining version of OpenSSL linked against python?

2012-01-23 Thread Adam Mercer
Hi

I'm trying to write a script that determines the version of OpenSSL
that python is linked against, using python-2.7 this is easy as I can
use:

import ssl
ssl.OPENSSL_VERSION

but unfortunately I need to support python-2.6, from an older script I
used the following:

import _ssl
ssl_lib = _ssl.__file__

to get the path to the _ssl.so module and then I parsed the output of
ldd (on linux) to get the path to the OpenSSL library and then parsed
the version from the filename. In other words it's very messy.

I had a little success using this approach but I have recently
received a bug report that this doesn't seem to work on Debian
Squeeze. When I try to query the __file__ attribute of the _ssl module
I get the following error:

>>> import _ssl
>>> _ssl.__file__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute '__file__'
>>>

Can anyone offer any suggestions as to what is going wrong with the
above code or offer an alternative way of determining the OpenSSl
version using python-2.6?

Cheers

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


Re: Determining version of OpenSSL linked against python?

2012-01-25 Thread Adam Mercer
Hi

Is this possible at all?

Cheers

Adam

On Mon, Jan 23, 2012 at 14:01, Adam Mercer  wrote:
> Hi
>
> I'm trying to write a script that determines the version of OpenSSL
> that python is linked against, using python-2.7 this is easy as I can
> use:
>
>    import ssl
>    ssl.OPENSSL_VERSION
>
> but unfortunately I need to support python-2.6, from an older script I
> used the following:
>
>    import _ssl
>    ssl_lib = _ssl.__file__
>
> to get the path to the _ssl.so module and then I parsed the output of
> ldd (on linux) to get the path to the OpenSSL library and then parsed
> the version from the filename. In other words it's very messy.
>
> I had a little success using this approach but I have recently
> received a bug report that this doesn't seem to work on Debian
> Squeeze. When I try to query the __file__ attribute of the _ssl module
> I get the following error:
>
>>>> import _ssl
>>>> _ssl.__file__
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'module' object has no attribute '__file__'
>>>>
>
> Can anyone offer any suggestions as to what is going wrong with the
> above code or offer an alternative way of determining the OpenSSl
> version using python-2.6?
>
> Cheers
>
> Adam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining version of OpenSSL linked against python?

2012-01-25 Thread Adam Mercer
On Wed, Jan 25, 2012 at 14:04, Terry Reedy  wrote:

> If you are not willing to tell Debian Squeeze users to install 2.7, or that
> they cannot run your program, ask the bug reporter to tell you what version
> of OpenSSL the system comes with and code it into your program.

I would like to only support python-2.7 as that would make a few other
things easier but the powers that be think otherwise, I unfortunately
need to target python-2.6.

> Or possibly, depending on what you do with the version info and what the
> differences are between versions, replace 'if version ...' constructs with
> 'try ... except...' constructs.

My code already has a try... except block that tries the
ssl.OPENSSL_VERSION approach first but I wanted to have a fallback
method that works with python-2.6. Looks like I may need to hardcode
certain things.

Cheers

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


Re: Determining version of OpenSSL linked against python?

2012-01-25 Thread Adam Mercer
On Wed, Jan 25, 2012 at 14:56, Nick Dokos  wrote:

> One other possibility is to parse the output of ssh -V:
>
> ,
> | $ ssh -V
> | OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
> | $ python
> | Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
> | [GCC 4.5.2] on linux2
> | Type "help", "copyright", "credits" or "license" for more information.
> | >>> import ssl
> | >>> ssl.OPENSSL_VERSION
> | 'OpenSSL 0.9.8o 01 Jun 2010'
> | >>>
> `
>
> This assumes that ssh and python would use the same version of openssl:
> not guaranteed, but seems like a "reasonable" assumption to me.

Hmm, I like that idea. Thanks for the suggestion.

Cheers

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


Re: Determining version of OpenSSL linked against python?

2012-01-25 Thread Adam Mercer
On Wed, Jan 25, 2012 at 15:21, Anssi Saari  wrote:

> I suppose you could use ctypes to load the library and call SSLeay()
> which returns the OpenSSL version number as a C long.
>
> Like this:
>
> from ctypes import *
> libssl = cdll.LoadLibrary("libssl.so")
> openssl_version = libssl.SSLeay()
> print "%.9X" % openssl_version
>
> This gives me 0009080FF which corresponds to 0.9.8o release which is
> what I have installed in Debian Squeeze.

Thanks, that looks useful.

Cheers

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


Re: multithreading

2012-04-07 Thread Adam Skutt
On Apr 7, 5:06 pm, Kiuhnm  wrote:
> On 4/7/2012 22:09, Bryan wrote:>> For instance, let's say I want to make this 
> code thread-safe:
>
> >> --->
> >> myDict = {}
>
> >> def f(name, val):
> >>       if name not in myDict:
> >>           myDict[name] = val
> >>       return myDict[name]
> >> <---
>
> > First, don't re-code Python's built-ins. The example is a job for
> > dict.setdefault().
>
> [...]
>
> That was just an example for the sake of the discussion.
> My question is this: can I use 'threading' without interfering with the
> program which will import my module?

'import threading' ought to work everywhere, but that's not enough to
tell you whether whatever you're trying to do will actually work.
However, you shouldn't need to do it unless your application is meant
to /only/ be used in applications that have done 'import threading'
elsewhere.  Otherwise, you probably have a pretty serious design
issue.

Global state is bad.  TLS state is little better, even if it's common
in a lot of python modules.  Non-thread-safe object instances is
usually fine.  Object construction needs to be thread-safe, but that's
also the default behavior.  You need not worry about it unless you're
doing very unusual things.

Plainly, most of the time you shouldn't need to do anything to support
multiples threads beyond avoiding global state.  In fact, you should
stop and give some serious thought to your design if you need to do
anything else.

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


  1   2   3   4   5   6   7   8   9   10   >