Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Thanks for the assistance and the article.

Neven

--

On Fri, May 21, 2010 at 5:35 PM, Lie Ryan  wrote:

> On 05/22/10 01:30, Neven Goršić wrote:
> > Thanks!
> > It's pity that Python has such unreliable functions so you never know in
> > advanced when you will hit new one ...
>
> Well, it's not Python but the machine. Floating point number is not Real
> numbers; there are certain limitations imposed by physical limitations.
>
> You can read: What Every Computer Scientist Should Know About
> Floating-Point Arithmetic:
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Thanks!
It's pity that Python has such unreliable functions so you never know in
advanced when you will hit new one ...

---

On Fri, May 21, 2010 at 2:14 PM, Lie Ryan  wrote:

> On 05/21/10 20:17, Neven Goršić wrote:
> > Hi!
> >
> > I run into Python error in rounding and not know how to predict when it
> will
> > occur in order to prevent wrong result.
>
> That's because it's floating point number.
>
> > What can I do to assure accurate result?
>
> Use decimal module to do precise control over your rounding.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Hi!

I run into Python error in rounding and not know how to predict when it will
occur in order to prevent wrong result.
What can I do to assure accurate result?

>>> "%.2f" % 0.445
'0.45'   correct
>>> "%.2f" % 0.455
'0.46'   correct
>>> "%.2f" % 0.465
'0.47'   correct
>>> "%.2f" % 0.475
'0.47'   not correct
>>> "%.2f" % 0.485
'0.48'   not correct
>>> "%.2f" % 0.495
'0.50'   correct

Neven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Raw string

2010-04-18 Thread Neven Goršić
Hi!

When I get file path from DirDialog, I get in a (path) variable.
Sometimes that string (path) contains special escape sequences, such as \x,
\r and so on.

 'C:\Python25\Programs\rating'

When I try to open that file (whose name contains escape sequences) it
doesn't work.

I know that raw string marker 'r' in front of string leaves char '\' as
character and not as start of escape sequences,
but I can not apply it to a variable name which contains file path.

Is there a function with same effect as raw string marker, as my problem
must be solved differently?

Can you help me?

Kind regards,

Neven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Menu data from file

2010-04-05 Thread Neven Goršić
OK, I will describe my "case".

I use menu date stored in list "shape" in file CMFlowData.py in the same
directory as my main program x.py. In the beginning of the program I have
command:

import CMFlowData

and everything works fine till I make executable with py2exe. There are no
error during "compilation" and exe are created in ...\dist directory. I copy
all my external files to that directory, together with CMFlowData.py file,
but when I run x.exe I get x.exe.log file with message:

Traceback (most recent call last):
  File "x.py", line 8, in 
ImportError: No module named CMFlowData
Traceback (most recent call last):
  File "x.py", line 8, in 
ImportError: No module named CMFlowData

All other files that I read from disk are created with relative paths and
work fine, except when I import
my own module.

Is there some procedure to "announce" my module to the Python or System?

That is all.

Neven



On Mon, Apr 5, 2010 at 4:03 PM, Lie Ryan  wrote:

> On 04/05/10 17:39, Neven Goršić wrote:
> > Thank you for mentioning the possible options.
> > I already use option where I import .py module,
> > but I run into troubles when making executable with py2exe.
>
> Maybe you should elaborate what problems you're experiencing with
> py2exe? Probably we can solve that instead of developing workarounds.
>
> Many popular UI toolkit provides an XML-based menu file.
> Here is one for PyGTK:
> http://www.pygtk.org/pygtk2tutorial/sec-UIManager.html
>
> You should better use your GUI toolkit's version instead of writing your
> own.
>
> > I suppose that XML approach is the most general method.
> > Can you recommend a good introduction text (not for experts :-))
> > and give more details about the tool ElementCTree.
> >
> > Maybe it will be educational and interesting for other beginners too.
>
> ElementTree is quite simple, though I don't think there are many good
> tutorials about it (at least I can't find one). In the simplest use
> case, you just use xml.etree.ElementTree.parse("menu.xml") and you can
> iterate the tree like so:
>
> import xml.etree.cElementTree as Et
> menuxml = """
> 
>  
>
>
>  
>  
>  
>
>
>  
>  
>
>
>  
> 
> """
> # root = Et.parse("menu.xml")
> root = Et.fromstring(menuxml)
>
> def parse(menutk, element):
>for menu in mbar:
>if menu.tag == 'menu':
># have submenus, recurse
>submenutk = add_menu(menutk)
>parse(submenutk, menu)
>elif emnu.tag == 'menuitem':
>add_menuitem(menutk, menuitem)
>
> or something like that.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Menu data from file

2010-04-05 Thread Neven Goršić
Thank you for mentioning the possible options.
I already use option where I import .py module,
but I run into troubles when making executable with py2exe.

I suppose that XML approach is the most general method.
Can you recommend a good introduction text (not for experts :-))
and give more details about the tool ElementCTree.

Maybe it will be educational and interesting for other beginners too.

Thanks,

Neven

-

On Mon, Apr 5, 2010 at 2:19 AM, Lie Ryan  wrote:

> On 04/05/10 08:54, Alan Gauld wrote:
> > Thats right you will need to parse the data to convert it into the
> > format you want.
> > This is one reason you might find it easier to use XML for storing the
> data
> > and use a tool like ElementCTree to parse it.
>
> s/ElementCTree/ElementTree/?
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Menu data from file

2010-04-04 Thread Neven Goršić
Hi!

I would like to import menu data from external txt file, but not as import
menudata.py, because then py2exe makes problems ...
I would like to preserve list structure like:

(("File",
   ("&New\tCtrl+N", "Create new blank script", self.onNew),
   ("&Open\tCtrl+O", "Opens call script", self.onOpen),
   ("","",""),
   ("&Save\tCtrl+S", "Saves call script", self.onSave),
  .  .  .

Thanks,

Neven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is wxPython (development) dead?

2010-01-27 Thread Neven Goršić
Since May of 2009 there has not been any update and now web page is not
available any more ...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Making exe Python file - standalone executable file

2009-03-17 Thread Neven Goršić
Hi!

Py2exe i standard way (up to my knowledge) of making standalone
executable Python file in order to distribute your program to others
who don't have Python installed (too bad that it is not part of
standard Python distribution). I have no experience with wxPython and
PyQT. Do they have their own compilers or we must do it again with
Py2exe?

Thanks,

Neven
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython vs PyQt

2009-03-16 Thread Neven Goršić
I just would like to correct my incomplete PyQT pricing list from
above and mislead none.

If you intent to write commercial programs you have to pay:

400 EURO   for PyQT AND3000 EURO  for QT !!!

-

On Tue, Mar 10, 2009 at 2:27 PM, andré palma  wrote:
> Neven Goršić wrote:
>>
>> Thank you all. It was not easy to decide what to learn/use, so I "Google"
>> some more.
>>
>> I have found that PyQT is more stable, faster, more consistent and more
>> expensive :).
>> 400 EURO is too much for playing around with some GUI, but GPL licence
>> resolves that issue.
>> The cons are C++ oriented documentation, editor and some structures ...
>>
>> Neven
>>
>> ---
>>
>> On Thu, Mar 5, 2009 at 3:10 AM, johnf > <mailto:jfabi...@yolo.com>> wrote:
>>
>>On Wednesday 04 March 2009 04:56:37 pm Alan Gauld wrote:
>>> "Kent Johnson" mailto:ken...@tds.net>> wrote
>>>
>>> > I've heard good things about Dabo, never tried it myself though.
>>> > http://dabodev.com/
>>>
>>> I looked at Dabo but decided not to try it since it was yet another
>>> framework. Although it's based on wxPython they have layered their
>>> own widgets on top which is what the GUI Builder uses. (PythonCard
>>> fell into the same hole)
>>
>>Yes, it's true that Dabo has wrapped (subclassed) most of the
>>controls. The
>>purpose of course was to provide developer ease of use.  If you
>>are building
>>a real business app then I doubt there is anything better in the
>>python
>>world.  I personally have used both VB and Delphi and see Dabo on
>>the same
>>level.  With one exception - we have a beta GUI builder.
>> Everything that has
>>been done in Dabo is the very same things that all developers would be
>>required to do if they access a database and associate fields to
>>controls.
>>BTW there is nothing stopping a Dabo developer from directly using wx
>>controls.  Dabo prevents nothing.
>>
>>So Alan, I don't see my work as falling into any hole.
>>>
>>> But the web pages and writeup looked good and the forum seemed
>>> to be active and not all negative.
>>>
>>> Alan G
>>
>
>>Hey, i've found your discussion interesting.
>>
> I'm developing my final course project and i'm using a toll called "Glade"
> to create my application. It has a IDE that let you to create your windows,
>  with text boxes, combo boxes ... everything! And the really good thing: it
> is totally open source =)
> It's quit simple to do applications with glade. You just have to create your
> GUI with it IDE and then you just need to link the "signals" to de functions
> that actually preform actions.
>
> GLADE:
> http://glade.gnome.org/
> http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm
>(examples how to use glade and pyGTK)
>
> and if you look for it in youtube there is a lot of a good video tutorials
>
>>
>>--
>>John Fabiani
>>___
>>Tutor maillist  -  Tutor@python.org <mailto:Tutor@python.org>
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython vs PyQt

2009-03-10 Thread Neven Goršić
Thank you all. It was not easy to decide what to learn/use, so I "Google"
some more.

I have found that PyQT is more stable, faster, more consistent and more
expensive :).
400 € is too much for playing around with some GUI, but GPL licence resolves
that issue.
The cons are C++ oriented documentation, editor and some structures ...

Neven

---

On Thu, Mar 5, 2009 at 3:10 AM, johnf  wrote:

> On Wednesday 04 March 2009 04:56:37 pm Alan Gauld wrote:
> > "Kent Johnson"  wrote
> >
> > > I've heard good things about Dabo, never tried it myself though.
> > > http://dabodev.com/
> >
> > I looked at Dabo but decided not to try it since it was yet another
> > framework. Although it's based on wxPython they have layered their
> > own widgets on top which is what the GUI Builder uses. (PythonCard
> > fell into the same hole)
>
> Yes, it's true that Dabo has wrapped (subclassed) most of the controls. The
> purpose of course was to provide developer ease of use.  If you are
> building
> a real business app then I doubt there is anything better in the python
> world.  I personally have used both VB and Delphi and see Dabo on the same
> level.  With one exception - we have a beta GUI builder.  Everything that
> has
> been done in Dabo is the very same things that all developers would be
> required to do if they access a database and associate fields to controls.
> BTW there is nothing stopping a Dabo developer from directly using wx
> controls.  Dabo prevents nothing.
>
> So Alan, I don't see my work as falling into any hole.
> >
> > But the web pages and writeup looked good and the forum seemed
> > to be active and not all negative.
> >
> > Alan G
>
>
>
>
> --
> John Fabiani
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] wxPython vs PyQt

2009-03-04 Thread Neven Goršić
Hi!

I am about to begin to learn GUI programming with Python. What are pros and
cons for PyQT and wxPython?

I read that PyQT has PyQT Designer which makes GUI programming easier. Is it
owned and supported by Nokia?
What about wxPython? Boa Constructor is not developed any more ... Is there
any program like QT Designer?
I read also that none of them are even near as good as Delphi or VB. Is it
really so?

Thanks,

Neven
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Raw string

2008-07-21 Thread Neven Goršić
2008/7/21 Martin Walsh <[EMAIL PROTECTED]>:
> Neven Goršić wrote:
>> I read from one file plenty of parameters and among them one file name
>> of other file.
>> That file name is 'e:\mm tests\1. exp files\5.MOC-1012.exp' and I hold
>> it in variable s.
>
> As John pointed out, if you're really reading this string from a file
> (with something like file.read or ConfigParser) it should already be
> escaped properly, and you'd get back something like 'e:\\mm tests\\1.
> exp files\\5.MOC-1012.exp' instead. Which would probably work for your
> purposes.
>
> Can you show us an example of the approach you're using to 'read'
> parameters from a file, including the variable assignment?
>
> Marty
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


I reconfigured file my parameter file. I left only one parameter in that line
(path) and write path without ''. Then f.readline() get correct raw string
and I can get path and file name properly by means of os.path.split(line).

Thank you for your good will

Neven Gorsic
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Raw string

2008-07-21 Thread Neven Goršić
On Mon, Jul 21, 2008 at 9:44 AM, Monika Jisswel
<[EMAIL PROTECTED]> wrote:
> instead  of s='e:\mm tests\1. exp files\5.MOC-1012.exp'
> try to use : s = r'e:\mm tests\1. exp files\5.MOC-1012.exp'.replace(
> '\\', '')
> for me here is what it gives:
>
 s = r'e:\mm tests\1. exp files\5.MOC-1012.exp'.replace('\\', '')
 print s
> e:\\mm tests\\1. exp files\\5.MOC-1012.exp
 s.split('')
> ['e:', 'mm tests', '1. exp files', '5.MOC-1012.exp']
>
>
> why \\  i you only have one \ ? : you need to escape it because its a
> special character to the python interpreter.
>
>
> the r character is important in the expression  s = r'e:\mm tests\1. exp
> files\5.MOC-1012.exp'.replace('\\', '') because it tells the interpreter
> to take the string as RAW and thus leave it unchanged even if it contains
> special characters that should actually be treated special.
>
> now to use the r or not to use it ? when to use it ? how to use it ? I
> always use it ! & always had the result I expected, so I would suggest you
> use it always too specialy with the re module, ofcourse unless the result is
> not satisaying you,
>
> so this code (using r this time works too) :
>
 s = r'e:\mm tests\1. exp files\5.MOC-1012.exp'.replace(r'\\', r'')
 print s
> e:\\mm tests\\1. exp files\\5.MOC-1012.exp
 s.split('')
> ['e:', 'mm tests', '1. exp files', '5.MOC-1012.exp']
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


Thanks,
I am aware of goodies that raw string offers, but my question was how to
use it with variable that already contains string.  :)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Raw string

2008-07-20 Thread Neven Goršić
On Sun, Jul 20, 2008 at 5:48 PM, Steve Willoughby <[EMAIL PROTECTED]> wrote:
> Neven Goršić wrote:
>>
>> Hi!
>>
>> In every manual and book I read only one way to make a raw string:
>> r"e:\mm tests\1. exp files\5.MOC-1012.exp".
>> I don't know how to make a string raw string if it is already
>> contained in a variable.
>> s.raw() or something like that ...
>
> Actually, there's no such thing as a "raw string" once it's constructed and
> sitting as an object in the runtime environment, or "contained in a string"
> as you stated.  It's just a string.  Raw strings simply refer to how the
> string constant value is assembled by the Python interpreter as the string
> object is being constructed.  In other words, it simply affects how the
> source code itself is understood to represent the string value.
>
> r"e:\mm tests\1. exp files\5.MOC-1012.exp" will create a string object with
> the characters "e:\mm tests\1. exp files\5.MOC-1012.exp".  But now that's
> just a string value.  From here on out, those are simply a collection of
> those individual character values and won't be interpreted further.
>
> "e:\mm tests\1. exp files\5.MOC-1012.exp" will create a string object with
> the characters "e:\mm tests^A. exp files^E.MOC-1012.exp".  But now that's
> just a string value with those characters.  There's no concept of "making it
> a raw string" after that point at all.
>>
>>
>>
>> Thank you very much
>>
>> PS. It seems like a very basic question but I can not find the answer
>> in few books.
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>


Thank You for your explanation. It seems that I have to explain in detail:


I read from one file plenty of parameters and among them one file name
of other file.
That file name is 'e:\mm tests\1. exp files\5.MOC-1012.exp' and I hold
it in variable s.

In program I need to know it's relative name and it's path.
When I try to get it with following commands I get wrong answers:

>>> s='e:\mm tests\1. exp files\5.MOC-1012.exp'
>>> os.path.split(s)
('e:\\', 'mm tests\x01. exp files\x05.MOC-1012.exp')
>>> os.path.dirname(s)
'e:\\'
>>> os.path.basename(s)
'mm tests\x01. exp files\x05.MOC-1012.exp'

instead of: 'e:\mm tests\1. exp files'   and   '5.MOC-1012.exp'.

The problem is that \1 and \5 is wrongly understood. I know that
everything works fine if I put raw string prefix r in front of string
which I put between "":

>>> os.path.split(r'e:\mm tests\1. exp files\5.MOC-1012.exp')
('e:\\mm tests\\1. exp files', '5.MOC-1012.exp')

but I can not do it that because I have already read path string
and it is now stored in variable s.

Maybe you wanted to suggest me to read from a file immediately
in a raw 'mode' but I don't know how to do that. Please tell me!

I solved that problem with 'workaround' witch works, but I am not
too happy with it:

def split_path(f_abs):
""" Extract path and relative file name from abs. path """
os.mkdir(f_abs+'_{}[]{}7x')  # create any subdirectory
os.chdir(f_abs+'_{}[]{}7x')   # go in
os.chdir('..')  # go back
os.rmdir(f_abs+'_{}[]{}7x')   # delete it (restore previous conditions)
f_path=os.getcwd()   # get current dir
f_rel=f_abs[1+len(f_path):] # 1 space because of '\'
return f_path, f_rel

Thanks for your consideration
Regards,

Neven Gorsic
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Raw string

2008-07-20 Thread Neven Goršić
Hi!

In every manual and book I read only one way to make a raw string:
r"e:\mm tests\1. exp files\5.MOC-1012.exp".
I don't know how to make a string raw string if it is already
contained in a variable.
s.raw() or something like that ...



Thank you very much

PS. It seems like a very basic question but I can not find the answer
in few books.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CD ROM Drive

2008-07-16 Thread Neven Goršić
2008/7/16 Neven Goršić <[EMAIL PROTECTED]>:
> On Wed, Jul 16, 2008 at 2:02 PM, Tim Golden <[EMAIL PROTECTED]> wrote:
>> Neven Goršić wrote:
>>>
>>> Hi!
>>>
>>> I am using Python 2.5.2 on WinXP Pro and I want to detect all disk drives.
>>> I have C:, D: and E: hard disks and F: DVD ROM.
>>
>> Use WMI:
>>
>> http://timgolden.me.uk/python/wmi_cookbook.html#find-drive-types
>>
>> (mutatis mutandis)
>>
>>
>>> When I try to use os.access method with writing checking I get True
>>> testing DVD ROM Drive with DVD media inside (which is not writable).
>>> 1. Why? DVD disk is not writable!
>>>
>>>>>> import os
>>>>>> print os.access('F:\\',os.W_OK)
>>>
>>> True
>>
>> In short because os.access always returns True for
>> *directories* as opposed to *files* on Windows
>> because it only checks the read-only flag and the
>> read-only flag has no real meaning on a directory
>> on Windows.
>>
>>> 2. When I remove DVD Disk from the drive I get unswer False.
>>
>>
>> It returns False when there's no media because that
>> constitutes an exception from the OS and the function
>> automatically returns False in that case.
>>
>> [... snip stuff about "Insert disk..." ...]
>>
>> Frankly this is a bit tricky. I'm not sure to what extent you can
>> get in ahead of the shell. A couple of possibilities, assuming
>> I've understood the situation. You can monitor device insertion
>> and removal either via the Win32 or shell APIs or via WMI (which, I imagine,
>> uses that API under the covers). The latest pywin32 modules have
>> added more support for this kind of thing, which you previously
>> had to do via ctypes.
>>
>> If you're interested in pursuing this, I can rustle up some code.
>>
>>> 3. Are there some other way to get list of all disk drives and DVD ROM
>>> drives?
>>> I hoped that I can do that with modules that comes with standard
>>> Python instalation.
>>
>> See above. Although my solution uses external modules[1][2], you *can* do
>> the same using ctypes, but why bother? Just install the
>> TJG
>>
>> [1] http://pywin32.sf.net
>> [2] http://timgolden.me.uk/python/wmi.html
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> ---
>
> Thank you for your quick answer. I'll try suggested modules and let you now.
>
> Neven
>
--


Dear Tim,

wmi package is not only elegant, but also capable of "silent"
interaction with Windows.
It doesn't couse Windows alerts which troubles me workig with
os.path.exists() method!

Thank you very much!


PS. In the begining wmi doesn't worked at all: import wmi passed, but
c = wmi.WMI()
caused a pile of errors. In the end I read Tony Cappellini
recomendation that we "may
need to run makepy manually on one or more of the following type libraries":

Microsoft WMI Scripting Library
WMI ADSI Extension Type Library
WMICntl Type Library

I run PythonWin, select Tools,Com Makepy and selecting previous libraries.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CD ROM Drive

2008-07-16 Thread Neven Goršić
On Wed, Jul 16, 2008 at 2:02 PM, Tim Golden <[EMAIL PROTECTED]> wrote:
> Neven Goršić wrote:
>>
>> Hi!
>>
>> I am using Python 2.5.2 on WinXP Pro and I want to detect all disk drives.
>> I have C:, D: and E: hard disks and F: DVD ROM.
>
> Use WMI:
>
> http://timgolden.me.uk/python/wmi_cookbook.html#find-drive-types
>
> (mutatis mutandis)
>
>
>> When I try to use os.access method with writing checking I get True
>> testing DVD ROM Drive with DVD media inside (which is not writable).
>> 1. Why? DVD disk is not writable!
>>
>>>>> import os
>>>>> print os.access('F:\\',os.W_OK)
>>
>> True
>
> In short because os.access always returns True for
> *directories* as opposed to *files* on Windows
> because it only checks the read-only flag and the
> read-only flag has no real meaning on a directory
> on Windows.
>
>> 2. When I remove DVD Disk from the drive I get unswer False.
>
>
> It returns False when there's no media because that
> constitutes an exception from the OS and the function
> automatically returns False in that case.
>
> [... snip stuff about "Insert disk..." ...]
>
> Frankly this is a bit tricky. I'm not sure to what extent you can
> get in ahead of the shell. A couple of possibilities, assuming
> I've understood the situation. You can monitor device insertion
> and removal either via the Win32 or shell APIs or via WMI (which, I imagine,
> uses that API under the covers). The latest pywin32 modules have
> added more support for this kind of thing, which you previously
> had to do via ctypes.
>
> If you're interested in pursuing this, I can rustle up some code.
>
>> 3. Are there some other way to get list of all disk drives and DVD ROM
>> drives?
>> I hoped that I can do that with modules that comes with standard
>> Python instalation.
>
> See above. Although my solution uses external modules[1][2], you *can* do
> the same using ctypes, but why bother? Just install the
> TJG
>
> [1] http://pywin32.sf.net
> [2] http://timgolden.me.uk/python/wmi.html
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

---

Thank you for your quick answer. I'll try suggested modules and let you now.

Neven
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CD ROM Drive

2008-07-16 Thread Neven Goršić
Hi!

I am using Python 2.5.2 on WinXP Pro and I want to detect all disk drives.
I have C:, D: and E: hard disks and F: DVD ROM.

When I try to use os.access method with writing checking I get True
testing DVD ROM Drive with DVD media inside (which is not writable).
1. Why? DVD disk is not writable!

>>> import os
>>> print os.access('F:\\',os.W_OK)
True

2. When I remove DVD Disk from the drive I get unswer False.
That is OK. But when I run program with that single command
from Windows Explorer I get Windows alert Window:

"No disk! Please insert a disk into drive F:"

That alert stops program and I must respond with: Cancel, Try again or Continue.
The alert remains even with try, except(WindowsError)

Interesting point is that that alert doesn't pop up before I open DVD
for the first time.
After first inserting and ejecting DVD media alert is here!

It seems that information that is DVD no longer avilable is not
updated accordingly.

How can I avoid that?

3. Are there some other way to get list of all disk drives and DVD ROM drives?
I hoped that I can do that with modules that comes with standard
Python instalation.


Thank you very much for your consideration

Neven
<>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor