Re: ANN: PyGUI 1.7.2-1
greg wrote: > I have uploaded a new PyGUI 1.7.2 package to correct > a couple of errors in the setup.py file. > > http://www.cosc.canterbury.ac.nz/~greg/python_gui/ > > - > > What is PyGUI? > -- > > PyGUI is an experimental highly-Pythonic cross-platform > GUI API. Implementations are currently available for > MacOSX and Gtk. For a full description of the project > goals, see the PyGUI web page at the above address. > > -- > Greg I downloaded the new version of PyGUI, but I am having some problems with running it in the IDLE ide. I will use BlobEdit.py as an example. If I run the the makefile, then blobedit runs ok as an application. If I use the terminal, and execute pythonw with argument blobedit.py, then it runs ok. However, if I try to run blobedit.py in the IDLE ide, I get an error since it tries to open a file when no file was given. Looking at your code, I see that you noticed certain situation where this occurs and tried to handle it by comparing path == sys.argv[0] and skipping opening the file in this case. But, when running it within IDLE, the path is equal to "8833" for some reason. I tried to hunt down where the problem occurs, but I was led to the method "application_openFile_(self, ns_app, path)" in the class _PyGui_NSApplication. I couldn't find out how this method ever got called though. Is there some way to work around this problem? Thanks. -- Bill Hale -- http://mail.python.org/mailman/listinfo/python-list
Help me please urgently!
Hi
How would I do this?
The teacher wants to keep track of the scores each member of the class obtains
in the quiz. There are three classes in the school and the data should be kept
separately for each class.
Here is my code:
import random
import operator
MATHS_OPERATIONS = [
(operator.add, "+"),
(operator.mul, "*"),
(operator.sub, "-")
]
NUM_QUESTIONS = 10
def get_int_input(prompt=''):
while True:
try:
return int(input(prompt))
except ValueError:
print("Not a valid input (integer is expected)")
def get_bool_input(prompt=''):
while True:
val = input(prompt).lower()
if val == 'yes':
return True
elif val == 'no':
return False
else:
print("Not a valid input (yes/no is expected)")
if __name__ == '__main__':
name = input("What is your name?").title()
class_name = input("What is your Class? ")
print(name, ", Welcome to the Maths Test")
score = 0
for _ in range(NUM_QUESTIONS):
num1 = random.randint(1,100)
num2 = random.randint(1,100)
op, symbol = random.choice(MATHS_OPERATIONS)
print("What is", num1, symbol, num2)
if get_int_input() == op(num1, num2):
print("Correct")
score += 1
else:
print("Incorrect")
print("Well done", name, "you scored", score, "/", NB_QUESTIONS)
filename = class_name + ".txt"
with open(filename, 'a') as f:
f.write(str(name) + " : " + str(score) + '\n')
if get_bool_input("Do you wish to view previous results for your class"):
with open(filename, 'r') as f:
print(f.read())
else:
input ("Press any key to exit")
Could somebody here me please?
--
https://mail.python.org/mailman/listinfo/python-list
Packages
I have a question on packages. Suppose I have a package P with modules A.py, B.py, and C.py. Suppose that C.py defines a class X. Assume that the package __init__.py file contains the statement "from C import X". If I write an external Python program H.py, then I can refer to the class X by doing: import P myX = P.X() My question is that I would like to use the same method for consistentcy sake for the modules A and B in the package. That is, if A needs to use the class X from C, I would like to do the following in the file A.py: import P aX = P.X() I tried this and it works. But, is there a problem with recursion here since C might refer to A, or B might refer to A and C refer to B? Is this even a good idea? Is there another way to achieve the consistency whether referring to class X from an external Python program or referring to class X from a sibling Python program in the package? Of course, the normal way to refer to class X in program A.py is to do the following: from C import X aX = X() Bill Hale -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE on Mac OS X
In article <[EMAIL PROTECTED]>, Furbybrain <[EMAIL PROTECTED]> wrote: > I'm running 10.3.9 and I've just installed Python 2.4. IDLE won't start- > it bounces in the dock once or twice then goes away. > I'm new to Python, and I'm trying to learn. Thanks. You might want to open the console window by running the application "Console" found in the Applications/Utilities folder. An error message may be there indicating what the problem is. -- Bill Hael -- http://mail.python.org/mailman/listinfo/python-list
Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!
Thank you, again, Michael, for all your help many months ago. I *FINALLY* got a HowTo done up; please see http://wiki.python.org/moin/HowTo/FileMagic I've also emailed Mr. Hupp to see if he'll re-post the SWIG version; he's working on a newer binding (forget... ctypes??) and once that one's working... :) But for now... Cheers, Larry REF: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4c60ec1599056df8/3eff4049a7bfdfc0?hl=en%E3%AD%82a54360c4d26&lnk=gst&q=python-magic#3eff4049a7bfdfc0 -- http://mail.python.org/mailman/listinfo/python-list
Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!
Thank you, again, Michael, for all your help many months ago. I *FINALLY* got a HowTo done up; please see http://wiki.python.org/moin/HowTo/FileMagic I've also emailed Mr. Hupp to see if he'll re-post the SWIG version; he's working on a newer binding (forget... ctypes??) and once that one's working... :) But for now... Cheers, Larry REF: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4c60ec1599056df8/3eff4049a7bfdfc0?hl=en%E3%AD%82a54360c4d26&lnk=gst&q=python-magic#3eff4049a7bfdfc0 -- http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
(quoted text below my reply) THANK YOU SO MUCH, Michael! Criminitly! Figures! HA! I had it the WHOLE TIME, but didn't realize it! ;) (As mentioned, I had FILE installed from GnuWin32.) DUH! I just neglected to do a search for "magic1.dll"... the most obvious of the obvious! I copied it from C:\Program Files\GnuWin32\bin\magic1.dll to C: \Program Files\python25\libs. Imports fine now. (I'll *test* it later. Then write-up my HowTo... I think I'll even see if I can make an EGG for others... SOUNDS "easy" with EasyInstall [http://peak.telecommunity.com/DevCenter/ EasyInstall]... I'll -see-... :) ) Ah, sometimes one CAN'T see the forest for the trees; a few hours hacking away at getting things going to THIS point will do it to ya... err, or at least "to me"! :D Thanks, again, Michael... -Larry On May 11, 11:34 am, Michael Torrie <[EMAIL PROTECTED]> wrote: > Larry Hale wrote: > > Now I *presume* my problem (at this point) is that I need to have > > libmagic named as "magic1.dll" -wherever- this module is looking for > > it. I'm just not sure, let alone if this is true, WHERE Python/ > > modules expect to find such things. > > > Also, which version(s)/file(s) should be placed where, or...?? > > The dll you are looking for is here: > > http://downloads.sourceforge.net/gnuwin32/file-4.21-bin.zip?modtime=1... > > The .dll.a file you mention is just a linker stub for when you want to > compile against it (as you are doing when building python-magic). > > The magic1.dll file in the file-4.21-bin.zip package should be placed > anywhere in the path. Since you'll be using it with python, you could > probably stick it in the python25/bin folder (where ever your python > system is installed). -- http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
After putting the magic1.dll file to C:\Program Files\Python25\DLLs (looking at the directory structure, that seemed as good a place as any), now I can *import* the module, but... >>> import magic >>> test = magic.Magic() Traceback (most recent call last): File "", line 1, in File "build\bdist.win32\egg\magic.py", line 32, in __init__ File "build\bdist.win32\egg\magic.py", line 72, in _check_error magic.MagicException: could not find any magic files! I've placed 474,146 magic 1,037,440 magic.mgc 32,203 magic.mime 45,696 magic.mime.mgc 77,312 magic1.dll into C:\windows\system32 in Windows/System PATH AND (simultaneously) C:\Program Files\python25\DLLs in sys.path/PYTHONPATH (I've also tried putting copies into different dirs in both PYTHONPATH and system PATH, to no avail.) Obviously, magic1.dll/magic.py (et al) can't FIND the needed file(s), but I'm not sure how to go about discerning WHERE it/they are looking - any thought(s)/suggestion(s), anyone?? Thanks in advance! -Larry P.S.: Thanks, again, Michael! ;) - L -- http://mail.python.org/mailman/listinfo/python-list
Re: Orlando Florida Python Tutor Needed
On May 10, 11:42 am, vbgunz <[EMAIL PROTECTED]> wrote: > I will pay anyone for a face-to-face tutoring in the Orlando Florida > area. I will pay $20.00 per hour (minimum 2 hours needed). What I need > are lessons in Decorators and Class methods. If I can walk away with > at least 5 lessons taught in both subjects I will be happy to offer an > additional $20.00. > > If you are interested in this offer feel free to either reply through > email OR here on this thread. There are no string attached, catches, > etc. I need to learn and if you can teach well, I will be happy to > learn. > > Best Regards > Victor B. Gonzalez I know you're looking for "one-on-one" help, direction, and/or tutelage, but since you've not received an answer (yet), here's some general info... --- For Class Methods, perhaps you could mention more of what you need to know? Otherwise, generically see: http://docs.python.org/tut/node11.html#SECTION001134 http://www.geocities.com/foetsch/python/new_style_classes.htm http://www.diveintopython.org/object_oriented_framework/defining_classes.html and obviously http://www.google.com/search?hl=en&q=python+class+methods&btnG=Google+Search --- For Decorators, have a gander at: http://www.ddj.com/web-development/184406073;jsessionid=QCNTPTSNXZP2WQSNDLPCKHSCJUNN2JVN?_requestid=749134 http://www.ibm.com/developerworks/linux/library/l-cpdecor.html and obviously http://www.google.com/search?hl=en&q=python+decorators&btnG=Google+Search Decorators are still rather new to -me-, and I've yet to "need" 'em, but they _seem_ like a handy feature. (Personally, I don't care too much for the syntax, but other than explicitly DOING what they do, which would be [1] messier and/or [2] non-transparent/duplicative, I sadly have no alternative thought[s]... ;) ) Cheers, -Larry Hale -- http://mail.python.org/mailman/listinfo/python-list
Re: list object
On May 10, 12:39 pm, Gandalf <[EMAIL PROTECTED]> wrote: > my manual contain chapter about lists with python. when i try to copy > paste : > > li = ["a", "b", "mpilgrim", "z", "example"] (1) > > it i get this errore: > > "TypeError: 'list' object is not callable" > > i was wondering if their is any special module I should import before > i use this function > > i know i ask foolish questions it's my first day with python and i > have experience only with PHP and javascript, so please be patient > > thanks To expand upon what others have already mentioned, and/or to explain what's going on... li ==>> a label for a "list" (presume the author used it as short- hand?); trying to set it to point-to/"equal"... ["a", "b", "mpilgrim", "z", "example"] ==>> THE LIST A "list" is a mutable (changeable in-place) container object. See e.g.: http://www.diveintopython.org/native_data_types/lists.html (1) ==>> the Python interpreter will interpret this as if you're attempting to "call" the list object (["a", "b", ...]) as if it were a function/method Indeed, the "(1)" is what's causing the problem, but it's -because- the list *object* is, well, "not callable". :) As an aside, see what "li" contains if you do: li = ["a", "b", "mpilgrim", "z", "example"][1] ;) Cheers! -Larry Hale -- http://mail.python.org/mailman/listinfo/python-list
Re: Saving an audio file's waveform into an image
On May 9, 1:55 am, Julien <[EMAIL PROTECTED]> wrote: > Hi, > > I would like to pull out the waveform of an audio file and save it > into an image file, for example in GIF format. Is that achievable, and > if so, how? > > I heard about the Snack module, but the project looks dead and un- > maintained. > > Your advice would be greatly appreciated. > > Thanks! > > Julien Would you please provide more info on what you're wanting to accomplish? As for "Snack module", all I could find was http://www.wanware.com/tsgdocs/snack.html, which seems "dead", although the Google cached version at http://64.233.167.104/search?q=cache:gNGrrPqY5RsJ:www.wanware.com/tsgdocs/snack.html+python+snack+module&hl=en&ct=clnk&cd=1&gl=us makes it sound rather UNlike what you're talking about. (Other ref's for my Google search of http://www.google.com/search?hl=en&q=python+snack+module&btnG=Google+Search seemed to show the same thing.) The short answer is: Huh?/What?/Why? Why not put the picture + sound ==> video file. (Sure the image remains static, but there's the Soundtrack with it! ;) ) Cheers, -Larry Hale -- http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
On May 10, 11:41 pm, Larry Hale <[EMAIL PROTECTED]> wrote: > I've heard tell of a Python binding for libmagic (file(1) *nixy > command; seehttp://darwinsys.com/file/). Generally, has anybody > built this and worked with it under Windows? > > The only thing I've been able to find is the python-magic module > athttp://hupp.org/adam/hg/python-magic/. > > [1] Is this "THE" python-magic module. (It seems to be to me, but > obviously I don't know. :) > > [2] Has anybody been able to build THIS version under Windows? > > I've gotten as far as completing the "setup.py install" process. > (After many troubles; I'll post the top-to-bottom HowTo-like info if/ > when I ever get it to work. :) > > At this point, there -is- a "magic" module that can be imported > (attempted-to, that is), but it fails. > > If I go to a cmd window, run the Py interpreter, and do "import magic" > I get: > > [1] an error pop-up (Windows window, which is blocking [as opposed > to "non-blocking", not "obscuring", though it does that, too] the cmd > window): > > (X) This application has failed to start because magic1.dll > was not found. Re-installing the application may fix this problem. > [OK] > > [2] then, within the interpreter, I get: > > Traceback (most recent call last): > File "", line 1, in > File "build\bdist.win32\egg\magic.py", line 2, in > File "build\bdist.win32\egg\cmagic.py", line 7, in > File "build\bdist.win32\egg\_cmagic.py", line 7, in > File "build\bdist.win32\egg\_cmagic.py", line 6, in > __bootstrap__ > ImportError: DLL load failed: The specified module could not > be found. > > I'm using Python 2.5 on Windows XP Pro. I've got CYGWIN installed > (more info can be provided if necessary) for a copy of file.exe (and > libmagic.a @ 357KB and libmagic.dll.a @ 25KB in C:\cygwin\lib). I > also have GNUWin32, also for file.exe alternatively (and > libmagic.dll.a @ ~ 8KB in C:\Program Files\GnuWin32\lib). > > magic.py in C:\Program Files\Python25\Lib\site-packages\magic-0.1- > py2.5-win32.egg imports cmagic.py (also in this egg), which imports > _cmagic.py, which has the following: > > def __bootstrap__(): >global __bootstrap__, __loader__, __file__ >import sys, pkg_resources, imp >__file__ = > pkg_resources.resource_filename(__name__,'_cmagic.pyd') >del __bootstrap__, __loader__ >imp.load_dynamic(__name__,__file__) > __bootstrap__() > > Now I *presume* my problem (at this point) is that I need to have > libmagic named as "magic1.dll" -wherever- this module is looking for > it. I'm just not sure, let alone if this is true, WHERE Python/ > modules expect to find such things. > > Also, which version(s)/file(s) should be placed where, or...?? > > Thanks for any/all help/pointers. I apologize up-front if I left out > any pertinent info; I'm paranoid about putting in too much (and some > that may be worthless) already... :) > > Cheers, > Larry Hale ALSO: I've even tried putting the 4 "magic" files INTO the .egg file... still no-go. :/ Thanks, all! -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
THANKS, AGAIN, for the reply! :) Okay, now I -really- feel silly... :> So, when I was going to try what you'd suggested, I noticed something peculiar: I hadn't "changed" anything on my system, but now, when I tried to "import magic" I got a missing DLL error. For a DIFFERENT DLL! This got me to thinking... Turns out, when I was having "success" earlier, I was -in- the C: \Program Files\GnuWin32\bin directory (where file.exe and related .dll files are). So I added C:\Program Files\GnuWin32\bin to the (system/Windows) PATH. Everything worked. I removed all the copious copies of the DLL, the magic files, etc., littering my hard drive in every other location. Still worked. 'Course, I don't honestly know why it didn't work with the files copied to other locales contained in the sys/Py paths... perhaps it was, as you mentioned, wanting the tree-structure to be the same? (I haven't the heart to check this out fully right now... *maybe* at a later time... ;) ) Yeah, I know. But HONESTLY! I could have -sworn- I'd already tried THAT... you know, all the "obvious"/"I've been programming/working in computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a 'hacker'..." stuff. I -swear-! [EGG ON FACE] [SIGH] Well, I'd say "live and learn", but I'm still scratching my head. But, 'nough of that. Thanks for your replies, Michael, and I'm off to work _with_ the module now, then work-up my HowTo (and experiment with making an "egg"?? ;) )... Caio! -Larry :P :) On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote: > Larry Hale wrote: > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg > > file... still no-go. :/ > > It's often the custom of programs ported from unix to windows to use the > dll location as a key to find the other files that are typically in > share, or etc. GTK, for example uses ../share and ../etc from the > location where the dlls are stored (if the dlls are in a folder called bin). > > In this case I'd try making a folder in the Python25 folder called > "share" and put the contents of the gnuwin32 share/file stuff in there. > Should look something like this: > > c:/python25/share/file/magic.mime.mgc > c:/python25/share/file/magic > c:/python25/share/file/magic.mgc > c:/python25/share/file/magic.mime > > Or, judging by a string I found in the dll itself, you might have to put > the files here: > > c:/progra~1/File/share/file/magic > > Although if such a path really is hardcoded into the dll, this is > certainly a bug, since it will fail on certain non-english windows systems. > > Anyway, who knows. Give these options a try. -- http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
On May 11, 11:42 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> THANKS, AGAIN, for the reply! :)
>
> Okay, now I -really- feel silly... :>
>
> So, when I was going to try what you'd suggested, I noticed something
> peculiar: I hadn't "changed" anything on my system, but now, when I
> tried to "import magic" I got a missing DLL error. For a DIFFERENT
> DLL! This got me to thinking...
>
> Turns out, when I was having "success" earlier, I was -in- the C:
> \Program Files\GnuWin32\bin directory (where file.exe and related .dll
> files are).
>
> So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
> PATH. Everything worked. I removed all the copious copies of the
> DLL, the magic files, etc., littering my hard drive in every other
> location. Still worked.
>
> 'Course, I don't honestly know why it didn't work with the files
> copied to other locales contained in the sys/Py paths... perhaps it
> was, as you mentioned, wanting the tree-structure to be the same? (I
> haven't the heart to check this out fully right now... *maybe* at a
> later time... ;) )
>
> Yeah, I know. But HONESTLY! I could have -sworn- I'd already tried
> THAT... you know, all the "obvious"/"I've been programming/working in
> computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
> 'hacker'..." stuff. I -swear-!
>
> [EGG ON FACE]
>
> [SIGH] Well, I'd say "live and learn", but I'm still scratching my
> head. But, 'nough of that. Thanks for your replies, Michael, and I'm
> off to work _with_ the module now, then work-up my HowTo (and
> experiment with making an "egg"?? ;) )...
>
> Caio!
> -Larry :P :)
>
> On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
>
> > Larry Hale wrote:
> > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > > file... still no-go. :/
>
> > It's often the custom of programs ported from unix to windows to use the
> > dll location as a key to find the other files that are typically in
> > share, or etc. GTK, for example uses ../share and ../etc from the
> > location where the dlls are stored (if the dlls are in a folder called bin).
>
> > In this case I'd try making a folder in the Python25 folder called
> > "share" and put the contents of the gnuwin32 share/file stuff in there.
> > Should look something like this:
>
> > c:/python25/share/file/magic.mime.mgc
> > c:/python25/share/file/magic
> > c:/python25/share/file/magic.mgc
> > c:/python25/share/file/magic.mime
>
> > Or, judging by a string I found in the dll itself, you might have to put
> > the files here:
>
> > c:/progra~1/File/share/file/magic
>
> > Although if such a path really is hardcoded into the dll, this is
> > certainly a bug, since it will fail on certain non-english windows systems.
>
> > Anyway, who knows. Give these options a try.
UPDATE: HOORAY!!! Well, actually, was about two steps forward, one
back. But I've gotten it all sorted out now! :)
I added C:\Program Files\GnuWin32\bin to the system/Windows PATH.
This takes care of the various required DLLs/libs.
The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
has the man pages. I'd overlooked these as they were only modified as
necessary; the "BSD" part made me think they'd be the same as the same
online versions I'd already read (that were *nix specific).
Obviously, I was wrong. These had the default paths to the magic*
files listed; C:\Program Files\File\share\file\.
If one creates said directory structure and moves/copies/unpacks the
magic ("database") files THERE, then one may do:
>>> import magic
>>> test = magic.Magic() # <-- New Magic class instance
>>> test.from_file( 'C:\\startrek.exe' ) # <-- Yeah, I have an old
Star Trek game file here to test with... :)
'MS-DOS executable, MZ for MS-DOS' # <-- This is what's
returned...
Alternately, if one wishes to leave/place the magic files elsewhere,
do like:
>>> test = magic.Magic( magic_file = 'C:\\Program Files\\GnuWin32\
\share\\file\\magic' ) # <-- spec where/what the file is
NOTE: Even if the "magic_file" location *is* specified, "mime = True"
still works fine. (Haven't checked, but I presume the source simply
tacks ".mime" to the filename automagically.) Obviously/also, one
needn't specify the argument names if one uses proper argument order:
magic.Magic( mime, magic_file ) :)
THANKS SO MUCH, Michael, for your answers and helping me alone the
way... :)
Cheers,
-Larry
--
http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
On May 11, 11:42 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> THANKS, AGAIN, for the reply! :)
>
> Okay, now I -really- feel silly... :>
>
> So, when I was going to try what you'd suggested, I noticed something
> peculiar: I hadn't "changed" anything on my system, but now, when I
> tried to "import magic" I got a missing DLL error. For a DIFFERENT
> DLL! This got me to thinking...
>
> Turns out, when I was having "success" earlier, I was -in- the C:
> \Program Files\GnuWin32\bin directory (where file.exe and related .dll
> files are).
>
> So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
> PATH. Everything worked. I removed all the copious copies of the
> DLL, the magic files, etc., littering my hard drive in every other
> location. Still worked.
>
> 'Course, I don't honestly know why it didn't work with the files
> copied to other locales contained in the sys/Py paths... perhaps it
> was, as you mentioned, wanting the tree-structure to be the same? (I
> haven't the heart to check this out fully right now... *maybe* at a
> later time... ;) )
>
> Yeah, I know. But HONESTLY! I could have -sworn- I'd already tried
> THAT... you know, all the "obvious"/"I've been programming/working in
> computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
> 'hacker'..." stuff. I -swear-!
>
> [EGG ON FACE]
>
> [SIGH] Well, I'd say "live and learn", but I'm still scratching my
> head. But, 'nough of that. Thanks for your replies, Michael, and I'm
> off to work _with_ the module now, then work-up my HowTo (and
> experiment with making an "egg"?? ;) )...
>
> Caio!
> -Larry :P :)
>
> On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
>
> > Larry Hale wrote:
> > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > > file... still no-go. :/
>
> > It's often the custom of programs ported from unix to windows to use the
> > dll location as a key to find the other files that are typically in
> > share, or etc. GTK, for example uses ../share and ../etc from the
> > location where the dlls are stored (if the dlls are in a folder called bin).
>
> > In this case I'd try making a folder in the Python25 folder called
> > "share" and put the contents of the gnuwin32 share/file stuff in there.
> > Should look something like this:
>
> > c:/python25/share/file/magic.mime.mgc
> > c:/python25/share/file/magic
> > c:/python25/share/file/magic.mgc
> > c:/python25/share/file/magic.mime
>
> > Or, judging by a string I found in the dll itself, you might have to put
> > the files here:
>
> > c:/progra~1/File/share/file/magic
>
> > Although if such a path really is hardcoded into the dll, this is
> > certainly a bug, since it will fail on certain non-english windows systems.
>
> > Anyway, who knows. Give these options a try.
UPDATE: HOORAY!!! Well, actually, was about two steps forward, one
back. But I've gotten it all sorted out now! :)
I added C:\Program Files\GnuWin32\bin to the system/Windows PATH.
This takes care of the various required DLLs/libs.
The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
has the man pages. I'd overlooked these as they were only modified as
necessary; the "BSD" part made me think they'd be the same as the same
online versions I'd already read (that were *nix specific).
Obviously, I was wrong. These had the default paths to the magic*
files listed; C:\Program Files\File\share\file\.
If one creates said directory structure and moves/copies/unpacks the
magic ("database") files THERE, then one may do:
>>> import magic
>>> test = magic.Magic() # <-- New Magic class instance
>>> test.from_file( 'C:\\startrek.exe' ) # <-- Yeah, I have an old
Star Trek game file here to test with... :)
'MS-DOS executable, MZ for MS-DOS' # <-- This is what's
returned...
Alternately, if one wishes to leave/place the magic files elsewhere,
do like:
>>> test = magic.Magic( magic_file = 'C:\\Program Files\\GnuWin32\
\share\\file\\magic' ) # <-- spec where/what the file is
NOTE: Even if the "magic_file" location *is* specified, "mime = True"
still works fine. (Haven't checked, but I presume the source simply
tacks ".mime" to the filename automagically.) Obviously/also, one
needn't specify the argument names if one uses proper argument order:
magic.Magic( mime, magic_file ) :)
THANKS SO MUCH, Michael, for your answers and helping me alone the
way... :)
Cheers,
-Larry
--
http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
On May 12, 1:34 am, Larry Hale <[EMAIL PROTECTED]> wrote: > The file source (previously linked from http://hupp.org/adam/hg/python-magic/) > has the man pages... Err... I meant "http://downloads.sourceforge.net/gnuwin32/file-4.21- bin.zip?modtime=1180175868&big_mirror=1"! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Module python-magic on/for Windows?
On May 12, 1:34 am, Larry Hale <[EMAIL PROTECTED]> wrote: > The file source (previously linked from http://hupp.org/adam/hg/python-magic/) > has the man pages... Err... I meant "http://downloads.sourceforge.net/gnuwin32/file-4.21- bin.zip?modtime=1180175868&big_mirror=1"! :) -- http://mail.python.org/mailman/listinfo/python-list
Python Behind a Squid Corporate Proxy on Windows
Greetings, Pythonistas!
My employer has a Squid Proxy between my Python programs and The
Internet.
I've searched high-and-low, and can only find examples online of how
to do basic authentication to connect TO an external Web Server, but
not how to go THROUGH a (corporate) Proxy, thus my question here.
I've tried all sorts of permutations based on my findings, but
(obviously) nothing's working for me. I've come across conflicting
information, including that urllib2 can't/won't do what I'm needing,
though this statement was a couple years old.
I'm running Python 2.5 on Windows XP SP2 64-bit. The Proxy is Squid
(don't know what version, but can find out if this is relevant).
urllib2 grabs the Proxy info fine: 'http': 'http://webfilter.xyz.local:
3128' (.getproxies()). There's the obvious necessity of telling
"something" my ID/pass *somehow*.
An example of one iteration:
##
import urllib2
proxy_handler = urllib2.ProxyHandler( { "http": "http://
myusername:@webfilter.xyz.local:3128" } )
opener= urllib2.build_opener( proxy_handler )
urllib2.install_opener( opener )
response = opener.open( "http://python.org"; )
print response
##
I've tried situations using HTTPPasswordMgrWithDefaultRealm and its
add_password method, also to no avail. (Again, THIS sort of thing
seems related to the -external- Web Server, _not_ going *through* a
Proxy. 'Course, I could be wrong. But if I am, I couldn't get this
to work, either. ;)
I've looked at what's happening with Wireshark; Py/my program/urllib2
makes the initial page request, Proxy replies HTTP Error 407: Proxy
Authentication Required, and Py/my program/urllib2 simply stops at
that, reporting the message/error.
Please forgive me; I've been programming in Python for a few years
now, but never had to deal with Web Proxies. I *have* tried to RTFMs,
but the "documentation" for non-basic stuffs with urllib2 is... uh...
well, I'm sure ye olde pro's know... :)
Cheers, and *any* help would be appreciated!
-Larry
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Behind a Squid Corporate Proxy on Windows
Err, the line above should be:
proxy_handler = urllib2.ProxyHandler( { "http": "http://
myusername:[EMAIL PROTECTED]:3128" } )
(Sorry! :)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Behind a Squid Corporate Proxy on Windows
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request, Squid replies "Error 407: Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)
I do appreciate your time, though! :)
-Larry
On Jul 18, 3:08 am, Chris <[EMAIL PROTECTED]> wrote:
> On Jul 17, 6:40 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
>
> > Err, the line above should be:
>
> > proxy_handler = urllib2.ProxyHandler( { "http": "http://
> > myusername:[EMAIL PROTECTED]:3128" } )
>
> > (Sorry! :)
>
> some old code I wrote to download public domain info for our company,
> also through a squid proxy and this still works for me
>
> import urllib2, urllib
>
> proxy = urllib2.ProxyHandler({'http': 'http://
> username:[EMAIL PROTECTED]:proxy_port'})
> auth = urllib2.HTTPBasicAuthHandler()
> opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
> urllib2.install_opener(opener)
>
> conn = urllib2.urlopen('http://python.org')
> return_str = conn.read()
>
> fp = open('python.html','w').write(return_str)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Behind a Squid Corporate Proxy on Windows
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request, Squid replies "Error 407: Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)
I do appreciate your time, though! :)
-Larry
On Jul 18, 3:08 am, Chris <[EMAIL PROTECTED]> wrote:
> On Jul 17, 6:40 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
>
> > Err, the line above should be:
>
> > proxy_handler = urllib2.ProxyHandler( { "http": "http://
> > myusername:[EMAIL PROTECTED]:3128" } )
>
> > (Sorry! :)
>
> some old code I wrote to download public domain info for our company,
> also through a squid proxy and this still works for me
>
> import urllib2, urllib
>
> proxy = urllib2.ProxyHandler({'http': 'http://
> username:[EMAIL PROTECTED]:proxy_port'})
> auth = urllib2.HTTPBasicAuthHandler()
> opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
> urllib2.install_opener(opener)
>
> conn = urllib2.urlopen('http://python.org')
> return_str = conn.read()
>
> fp = open('python.html','w').write(return_str)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Behind a Squid Corporate Proxy on Windows
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request, Squid replies "Error 407: Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)
I do appreciate your time, though! :)
-Larry
On Jul 18, 3:08 am, Chris <[EMAIL PROTECTED]> wrote:
> On Jul 17, 6:40 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
>
> > Err, the line above should be:
>
> > proxy_handler = urllib2.ProxyHandler( { "http": "http://
> > myusername:[EMAIL PROTECTED]:3128" } )
>
> > (Sorry! :)
>
> some old code I wrote to download public domain info for our company,
> also through a squid proxy and this still works for me
>
> import urllib2, urllib
>
> proxy = urllib2.ProxyHandler({'http': 'http://
> username:[EMAIL PROTECTED]:proxy_port'})
> auth = urllib2.HTTPBasicAuthHandler()
> opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
> urllib2.install_opener(opener)
>
> conn = urllib2.urlopen('http://python.org')
> return_str = conn.read()
>
> fp = open('python.html','w').write(return_str)
--
http://mail.python.org/mailman/listinfo/python-list
Help Tracing urllib2 Error, Please?
Since it seems I have a "unique" problem, I wonder if anyone could point me in the general/right direction for tracking down the issue and resolving it myself. See my prior post @ http://groups.google.com/group/comp.lang.python/browse_thread/thread/44775994a6b55161?hl=en# for more info. (Python 2.5.2 on Win XP 64 ==>> Squid Proxy requiring Authentication ==>> Internet not working.) I've looked the urllib2 source over, but am having trouble following it. As previously mentioned, urllib2 initiates the request, Squid replies "407 error" that auth's required, and then urllib2 just stops, throwing error 407. Any though(s) on what to check out? It's frustrating (to say the least) that it seems so many are successfully accomplishing this task, and all's working perfectly for them, but I'm failing miserably. Would any quotes viewed in the HTTP traffic help? (Wireshark shows all! :) I don't even know what other info could help. Any info to get about Squid's configuration that might make it "non standard" in a way that could cause my problem? Any question(s) I should ask my Net Admin to relay info to you all? As always, any/all help greatly appreciated. Thanks! :) -Larry -- http://mail.python.org/mailman/listinfo/python-list
Module python-magic on/for Windows?
I've heard tell of a Python binding for libmagic (file(1) *nixy command; see http://darwinsys.com/file/). Generally, has anybody built this and worked with it under Windows? The only thing I've been able to find is the python-magic module at http://hupp.org/adam/hg/python-magic/. [1] Is this "THE" python-magic module. (It seems to be to me, but obviously I don't know. :) [2] Has anybody been able to build THIS version under Windows? I've gotten as far as completing the "setup.py install" process. (After many troubles; I'll post the top-to-bottom HowTo-like info if/ when I ever get it to work. :) At this point, there -is- a "magic" module that can be imported (attempted-to, that is), but it fails. If I go to a cmd window, run the Py interpreter, and do "import magic" I get: [1] an error pop-up (Windows window, which is blocking [as opposed to "non-blocking", not "obscuring", though it does that, too] the cmd window): (X) This application has failed to start because magic1.dll was not found. Re-installing the application may fix this problem. [OK] [2] then, within the interpreter, I get: Traceback (most recent call last): File "", line 1, in File "build\bdist.win32\egg\magic.py", line 2, in File "build\bdist.win32\egg\cmagic.py", line 7, in File "build\bdist.win32\egg\_cmagic.py", line 7, in File "build\bdist.win32\egg\_cmagic.py", line 6, in __bootstrap__ ImportError: DLL load failed: The specified module could not be found. I'm using Python 2.5 on Windows XP Pro. I've got CYGWIN installed (more info can be provided if necessary) for a copy of file.exe (and libmagic.a @ 357KB and libmagic.dll.a @ 25KB in C:\cygwin\lib). I also have GNUWin32, also for file.exe alternatively (and libmagic.dll.a @ ~ 8KB in C:\Program Files\GnuWin32\lib). magic.py in C:\Program Files\Python25\Lib\site-packages\magic-0.1- py2.5-win32.egg imports cmagic.py (also in this egg), which imports _cmagic.py, which has the following: def __bootstrap__(): global __bootstrap__, __loader__, __file__ import sys, pkg_resources, imp __file__ = pkg_resources.resource_filename(__name__,'_cmagic.pyd') del __bootstrap__, __loader__ imp.load_dynamic(__name__,__file__) __bootstrap__() Now I *presume* my problem (at this point) is that I need to have libmagic named as "magic1.dll" -wherever- this module is looking for it. I'm just not sure, let alone if this is true, WHERE Python/ modules expect to find such things. Also, which version(s)/file(s) should be placed where, or...?? Thanks for any/all help/pointers. I apologize up-front if I left out any pertinent info; I'm paranoid about putting in too much (and some that may be worthless) already... :) Cheers, Larry Hale -- http://mail.python.org/mailman/listinfo/python-list
