Problem connecting to SMTP/IMAP server using SSL
Hi, I'm able to connect to an Exchange server via SMTP and IMAP from my iPhone using SSL and without using a VPN. So I would expect to be able to do the same from my computer using Python. However, the following hangs and times out on my computer when I'm not connected to the VPN: >>> import imaplib >>> imap = imaplib.IMAP4_SSL("my.server.address") If I am connected to the VPN, then it works fine. Do you know why it won't work with SSL and without the VPN? Am I missing something? Thanks a lot, Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem connecting to SMTP/IMAP server using SSL
Hi Michael, Thanks for your reply. I did try port 993. I know that port generally works for me, as I can access the Gmail IMAP/SMTP server using SSL. It also works for that other Exchange server but only when the VPN is turned on. Somehow my iPhone works fine without a VPN, as long as it uses SSL. So I'm really unsure why I can't achieve the same thing from my laptop using imaplib.IMAP4_SSL() without the VPN turned on. Thank you, Julien On Apr 2, 3:10 pm, Michael Hrivnak wrote: > That method uses the default port 993. Can you connect to that port > at all from your computer? For example, try using a telnet client. > > Michael > > On Sat, Mar 31, 2012 at 1:39 AM, Julien wrote: > > Hi, > > > I'm able to connect to an Exchange server via SMTP and IMAP from my > > iPhone using SSL and without using a VPN. So I would expect to be able > > to do the same from my computer using Python. > > > However, the following hangs and times out on my computer when I'm not > > connected to the VPN: > > >>>> import imaplib > >>>> imap = imaplib.IMAP4_SSL("my.server.address") > > > If I am connected to the VPN, then it works fine. > > > Do you know why it won't work with SSL and without the VPN? Am I > > missing something? > > > Thanks a lot, > > > Julien > > -- > >http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Custom dict to prevent keys from being overridden
Hi, With a simple dict, the following happens: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } >>> d {'a': 3, 'b': 2} ... i.e. the value for the 'a' key gets overridden. What I'd like to achieve is: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } Error: The key 'a' already exists. Is that possible, and if so, how? Many thanks! Kind regards, Julien -- http://mail.python.org/mailman/listinfo/python-list
Problem with keyboard up/down arrows in Python 2.4 interpreter
Hi, I'm having problems when typing the up/down arrows in the Python 2.4 interpreter (exact version: Python 2.4.6 (#1, Mar 3 2011, 15:45:53) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin). When I press the up arrow it outputs "^[[A" and when I press the down arrow it outputs "^[[B". I've google it and it looks like it might be an issue with the readline not being installed or configured properly. Is that correct? If so, how can I fix this issue? Many thanks. Kind regards, Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with keyboard up/down arrows in Python 2.4 interpreter
On Mar 22, 5:37 pm, Benjamin Kaplan wrote: > On Tue, Mar 22, 2011 at 2:27 AM, Julien wrote: > > Hi, > > > I'm having problems when typing the up/down arrows in the Python 2.4 > > interpreter (exact version: Python 2.4.6 (#1, Mar 3 2011, 15:45:53) > > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin). > > > When I press the up arrow it outputs "^[[A" and when I press the down > > arrow it outputs "^[[B". > > > I've google it and it looks like it might be an issue with the > > readline not being installed or configured properly. Is that correct? > > If so, how can I fix this issue? > > > Many thanks. > > > Kind regards, > > > Julien > > -- > > How did you install Python? If you used Macports, it looks like > readline support is a separate port for 2.4. Try installing > py-readline. > > > > > > > > >http://mail.python.org/mailman/listinfo/python-list Hi, Which readline package should I install? I've tried with 'pip install py-readline' but that package doesn't seem to exist. I've tried with 'pyreadline' (without the dash) but that didn't fix the issue. Many thanks, Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with keyboard up/down arrows in Python 2.4 interpreter
On Mar 25, 6:35 pm, Ned Deily wrote: > In article > , > Benjamin Kaplan wrote: > > > As I stated above, py-readline is for if you're using Macports, which > > is a package manager for Mac OS X. > > ... in which case you probably want: > > sudo port install py-readline > > > If you installed Python through > > some other means, I'm not sure why you don't have readline installed > > already, because it should be built with the rest of the Python > > modules. > > For releases prior to Python 2.6 and Python 3.2, to build the Python > readline module, you need to have installed a local version of the GNU > readline library, a library which is not included in Mac OS X. Starting > with Python 2.6 and with a deployment target of Mac OS X 10.5 or higher, > the Python readline module will be automatically linked with the > Apple-supplied BSD editline (libedit) library. > > P.S to Julien: Python 2.4 is *really* old now and is no longer supported > by the Python developers. It probably won't build correctly on current > OS X 10.6 without some help. Python 2.7.1 and Python 3.2 are the > current releases. > > -- > Ned Deily, > n...@acm.org Thank you Ned and Benjamin, and sorry for the confusion :) I did install python2.4 using Mac Ports, and as you've suggested I've just installed py-readlines using Mac Ports as well, and it now works! Many thanks! Julien -- http://mail.python.org/mailman/listinfo/python-list
Shortcutting the function call stack
Hello all, I would like to do something like: def called(arg) if arg==True: !!magic!!caller.return 1 def caller(arg) called(arg) return 2 Here, the fake !!!magic!!! represents a statement (which I ignore) that would make the caller function return a value different from what it'd return normally. For example, caller(True) would return 1, and caller(False) would return 2. The reason I want that is because I don't want the caller function to know what's going on in the called function, and be shortcut if the called function think it's necessary. Would you know if that's possible, and if so, how? I've done a bit of research and I think I've found some good pointers, in particular using the 'inspect' library: import inspect def called(arg) if arg==True: caller_frame = inspect.stack()[1] ... Here 'caller_frame' contains the frame of the caller function. Now, how can I make that frame return a particular value? By the way, I'm not really interested in 'called' throwing an exception and 'caller' catching it. In fact, I want things to remain completely transparent for 'caller'. Hope that was clear... :/ Thanks! Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Shortcutting the function call stack
Hi all, and thanks a lot for your answers! I'll try to explain a bit more what I'm after, and hopefully that will be clearer. In fact, what I'm trying to do is to "hijack" (I'm making up the term) a function: def hijacker(arg): if I_feel_its_necessary: hijack_caller_function_and_make_it_return(1) def my_function1(arg): hijacker(something) ... # Continue as normal return 2 def my_function2(arg): ... # Maybe do some processing here hijacker(whatever) ... # Continue as normal return 3 I have some long functions like my_function1 and my_function2 which I'd like to alter, but I want to keep the alterations as little as as possible. I'd like the extra behaviour to be handled by 'hijacker' and let it decide what the caller function should return. Just adding a call to 'hijacker' in all of these functions would be ideal for me because that would be quick to modify them and also easier to maintain, I believe. If 'hijacker' thinks it's necessary, it would force the caller function to return a certain value, otherwise it would let the caller function do its normal business. For while I thought I'd make hijacker a decorator: @hijacker def my_function(request): But that wouldn't work, since some functions need to do some processing before calling the hijacker. Yet, I think a decorator is systematically called before the function itself so no prior processing can be done by the function... Any idea on how to do that, if that's even possible? Thanks! Julien On Mar 25, 2:06 am, [EMAIL PROTECTED] wrote: > On Mar 24, 9:48 am, Jason <[EMAIL PROTECTED]> wrote: > > > > > On Mar 24, 5:21 am, Julien <[EMAIL PROTECTED]> wrote: > > > > Hello all, > > > > I would like to do something like: > > > > def called(arg) > > > if arg==True: > > > !!magic!!caller.return 1 > > > > def caller(arg) > > > called(arg) > > > return 2 > > > > Here, the fake !!!magic!!! represents a statement (which I ignore) > > > that would make the caller function return a value different from what > > > it'd return normally. > > > > For example, caller(True) would return 1, and caller(False) would > > > return 2. The reason I want that is because I don't want the caller > > > function to know what's going on in the called function, and be > > > shortcut if the called function think it's necessary. > > > > Would you know if that's possible, and if so, how? > > > > I've done a bit of research and I think I've found some good pointers, > > > in particular using the 'inspect' library: > > > > import inspect > > > > def called(arg) > > > if arg==True: > > > caller_frame = inspect.stack()[1] > > > ... > > > > Here 'caller_frame' contains the frame of the caller function. Now, > > > how can I make that frame return a particular value? > > > > By the way, I'm not really interested in 'called' throwing an > > > exception and 'caller' catching it. In fact, I want things to remain > > > completely transparent for 'caller'. > > > > Hope that was clear... :/ > > > > Thanks! > > > > Julien > > > As Steven wrote, it's not very clear. If we knew the intent of this, > > we could perhaps point you to a more useful, maintainable technique. > > We don't know why you're trying to circumvent the programming language > > in this case. Any solution that works as you described will probably > > be unportable between the different Pythons (CPython, Jython, > > IronPython, etc). > > > Please note that the following code should work, but I've only run it > > through the interpreter in my brain. My brain's interpreter is full > > of Heisenbugs, so you may need to adjust a few things. Here's my > > thoughts: > > > Given: > > def First( arg ): > > Second( arg ) > > return 5 > > > 1) If you can modify both functions, change the first function to > > return a value in certain circumstances: > > def AltFirst( arg ): > > value = Second( arg ) > > if value is not None: return value > > return 5 > > > 2) Raise an exception in Second, and catch that exception above > > First: > > > class SecondExcept(Exception): > > def __init__(self, value): > > Exception.__init__(self, 'Spam!') > > s
Unnormalizing normalized path in Windows
Hi, In Windows, when a path has been normalized with os.path.normpath, you get something like this: C:/temp/my_dir/bla.txt # With forward slashes instead or backward slashes. Is it possible to revert that? >>> magic_function('C:/temp/my_dir/bla.txt') 'C:\temp\my_dir\bla.txt' I wonder if there's a standard function to do that... Thanks a lot! Julien -- http://mail.python.org/mailman/listinfo/python-list
Remove some characters from a string
Hi, I can't seem to find the right regular expression to achieve what I want. I'd like to remove all characters from a string that are not numbers, letters or underscores. For example: >>> magic_function('[EMAIL PROTECTED]') str: 'si_98udasgf' Would you have any hint? Thanks a lot! Julien -- http://mail.python.org/mailman/listinfo/python-list
Issue with regular expressions
Hi, I'm fairly new in Python and I haven't used the regular expressions enough to be able to achieve what I want. I'd like to select terms in a string, so I can then do a search in my database. query = ' " some words" with and "withoutquotes " ' p = re.compile(magic_regular_expression) $ <--- the magic happens m = p.match(query) I'd like m.groups() to return: ('some words', 'with', 'and', 'without quotes') Is that achievable with a single regular expression, and if so, what would it be? Any help would be much appreciated. Thanks!! Julien -- http://mail.python.org/mailman/listinfo/python-list
Saving an audio file's waveform into an image
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 -- http://mail.python.org/mailman/listinfo/python-list
Listing modules from all installed packages
Hi, I'm trying to write a function that programmatically obtains and returns the exact location of all first-level modules for all installed packages. For example, if the packages named 'django' and 'django-debug-toolbar' are installed, I'd like this function to return something like: >>> installed_modules() /Users/my_user/.virtualenvs/my_venv/lib/python2.6/site-packages/django /Users/my_user/.virtualenvs/my_venv/src/debug_toolbar That is, this function needs to consider all installed packages, including those that have been installed in "edit" mode (i.e. in the src/ folder). Note also that the main module for the 'django-debug-toolbar' is in fact named 'debug_toolbar'. So far the closest I've been to retrieving the list of first-level modules is as follows: import os import pkg_resources import setuptools pkgs = set() for dist in pkg_resources.working_set: if os.path.isdir(dist.location): for pkg in setuptools.find_packages(dist.location): if '.' not in pkg: pkgs.add(pkg) The idea is then to loop through that list of modules, import them and get their exact locations by fetching their __file__ attribute values. However, this feels very hackish and I don't think it's actually quite correct either. I'm sure there must be a better way. If possible I'd also like to avoid having to use setuptools. Do you have any tips on how to achieve this? Many thanks! Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Listing modules from all installed packages
On Saturday, June 8, 2013 11:22:16 PM UTC-7, Carlos Nepomuceno wrote: > Just realized that you've asked for installed packages. Perhaps the following > will do the trick. I don't know why the 'lib-tk' isn't included. Why not? > > toplevel_packages = ['%s\\%s'%(ml.path,name)for ml,name,ispkg in > pkgutil.iter_modules() if ispkg] > print '\n'.join(toplevel_packages) Thanks a lot Carlos, this gives me exactly what I needed! Best wishes, Julien -- http://mail.python.org/mailman/listinfo/python-list
Preserving unicode filename encoding
Hi, I've noticed that the encoding of non-ascii filenames can be inconsistent between platforms when using the built-in open() function to create files. For example, on a Ubuntu 10.04.4 LTS box, the character u'ş' (u'\u015f') gets encoded as u'ş' (u's\u0327'). Note how the two characters look exactly the same but are encoded differently. The original character uses only one code (u'\u015f'), but the resulting character that is saved on the file system will be made of a combination of two codes: the letter 's' followed by a diacritical cedilla (u's\u0327'). (You can learn more about diacritics in [1]). On the Mac, however, the original encoding is always preserved. This issue was also discussed in a blog post by Ned Batchelder [2]. One suggested approach is to normalize the filename, however this could result in loss of information (what if, for example, the original filename did contain combining diacritics and we wanted to preserve them). Ideally, it would be preferable to preserve the original encoding. Is that possible or is that completely out of Python's control? Thanks a lot, Julien [1] http://en.wikipedia.org/wiki/Combining_diacritic#Unicode_ranges [2] http://nedbatchelder.com/blog/201106/filenames_with_accents.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem connecting to SMTP/IMAP server using SSL
Hi Michael, Thanks again for your reply. I've tried using SMTP with TLS. And again it works with the VPN turned on but it still won't work with the VPN turned off. For some reason I don't understand, it simply won't instantiate the SMTP/SMTP_SSL/IMAP4/IMAP4_SSL objects at all and will hang forever if the VPN is turned off. I'm really at loss there :) Julien On Apr 2, 2012, at 6:57 PM, Michael Hrivnak wrote: > Your phone may be using TLS on the normal IMAP port (143). Or, are > you sure your phone is using IMAP and not active sync? > > Michael > > On Mon, Apr 2, 2012 at 6:25 PM, Julien wrote: >> Hi Michael, >> >> Thanks for your reply. I did try port 993. I know that port generally >> works for me, as I can access the Gmail IMAP/SMTP server using SSL. It >> also works for that other Exchange server but only when the VPN is >> turned on. >> >> Somehow my iPhone works fine without a VPN, as long as it uses SSL. So >> I'm really unsure why I can't achieve the same thing from my laptop >> using imaplib.IMAP4_SSL() without the VPN turned on. >> >> Thank you, >> >> Julien >> >> On Apr 2, 3:10 pm, Michael Hrivnak wrote: >>> That method uses the default port 993. Can you connect to that port >>> at all from your computer? For example, try using a telnet client. >>> >>> Michael >>> >>> On Sat, Mar 31, 2012 at 1:39 AM, Julien wrote: >>>> Hi, >>> >>>> I'm able to connect to an Exchange server via SMTP and IMAP from my >>>> iPhone using SSL and without using a VPN. So I would expect to be able >>>> to do the same from my computer using Python. >>> >>>> However, the following hangs and times out on my computer when I'm not >>>> connected to the VPN: >>> >>>>>>> import imaplib >>>>>>> imap = imaplib.IMAP4_SSL("my.server.address") >>> >>>> If I am connected to the VPN, then it works fine. >>> >>>> Do you know why it won't work with SSL and without the VPN? Am I >>>> missing something? >>> >>>> Thanks a lot, >>> >>>> Julien >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list >> >> -- >> http://mail.python.org/mailman/listinfo/python-list smime.p7s Description: S/MIME cryptographic signature -- http://mail.python.org/mailman/listinfo/python-list
python distributed computing
Hello the list, I have a, let say 'special' , request. I would like to make a very specific type of distributed computing. Let me explain myself : I have a HUGE(everything is relative) amount of data coming from UDP/514 ( good old syslog), and one process alone could not handle them ( it's full of regex, comparison and counting. all this at about 100K lines of data per seconds and each line is about 1500o long. I tried to handle it on one process, 100% core time in htop. ) So i said to myself : why not distribute the computing ? I looked for a good library that could do the distribution/process management job for me (http://wiki.python.org/moin/ParallelProcessing). What i found was not really usable by me ( distributed processing with a lot of processing but almost no process communication wich is the opposite of the thing i would like to do: distribute the events in real time so it is processed in real time.). My question is : is their any library or API or anything that is able to do that ? Sincerly Julien PS: This is my first time posting on any mailing list, my explanation/syntax could look a little bite, messy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Lies in education [was Re: The "loop and a half"]
Le 12/10/2017 à 17:57, bartc a écrit : With a const struct, you are stopped from directly modifying elements, but if an element is a pointer, nothing stops you writing to what the pointer points to, unless that has a const target too. And then you've going to have problems doing normal updates. This constness just insinuates itself everywhere. That is not very different from the mutable/immutable concept in Python, is it ? A tuple is immutable, but if it contains a mutable object, nothing prevents you from mutating it. Does it mean you think the mutable/immutable concept of Python is flawed? Julien -- https://mail.python.org/mailman/listinfo/python-list
Re: Spectre/Meltdown bug affecting Python ?
Le 06/01/2018 à 21:49, J.O. Aho a écrit : Not just Linux, but all other OS:es, Microsoft and Apple been patching in secret as they have a closed source approach, but ms-windows needs at least one more patch before it can breath out, which will be released on Tuesday. As a matter of fact, Apple kernel, xnu, is not closed source, https://opensource.apple.com/source/xnu/ -- https://mail.python.org/mailman/listinfo/python-list
Matplotlib scale
Hi everyone, I've created a code to run a 2D mapping using matplotlib from a .csv file. I've tried to set the maximum color (red) of the scale as 80% of the maximum value and not as the maximum value of my .csv file. Does someone know how to modify that? I've tried different solution but it doesn't work. Thanks import os import matplotlib.pyplot as plt import pandas as pd import numpy as np from matplotlib import colorbar, colors import matplotlib.tri as tri #os.chdir("C:/Users/Julien Hofmann/Desktop/Nano-indentation") data = pd.read_csv("Cartographie.csv",sep=';') nb_lignes=21 nb_colonnes=27 fig = plt.figure(figsize=(15,12)) ax = plt.subplot(1,1,1) x=np.linspace(0,(data["x"][len(data["x"])-1]-data["x"][0])*1000,nb_colonnes) y=np.linspace(0,(data["y"][len(data["y"])-1]-data["y"][0])*1000,nb_lignes) X,Y=np.meshgrid(x,y) z=np.array(data["Durete"]) triang = tri.Triangulation(data["x"], data["y"]) interpolator = tri.LinearTriInterpolator(triang, z) Xi, Yi = np.meshgrid(x, y) zi = interpolator(Xi, Yi) cntr1 = ax.contourf(x, y, z.reshape(nb_lignes,nb_colonnes), levels=150, cmap="jet") cbar = fig.colorbar(cntr1, ax=ax) ax.axis('on') -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib scale
Le lundi 5 avril 2021 à 21:50:49 UTC+2, David Lowry-Duda a écrit : Thank you for your response! I just tried it but it doesn't make what I want. Bassically, I would like to not put any color for every values above 0.8 times the maximum value (ie. 488). Hence, the ''maximum'' color (ie. red) would correspond to 488 and not to 610 as currently. -- https://mail.python.org/mailman/listinfo/python-list
Re: Matplotlib scale
Thank you for your response, and thank you for the different tips concerning visualisation. I'll improve it. I've tried to put vmin and vmax in contourf(). It works but the values above 80% of the maximum value still remain red which makes the cartography not really clear. I think I should in black, or white, every values above 80% of the maximum value. -- https://mail.python.org/mailman/listinfo/python-list
Knowing which thread had the GIL before
Hi, I've worked the past few days on a stastistical sampling profiling tool for an online Python 2.7 service that runs on Windows. My approach so far is: - I have a dedicated thread that sleeps most of the time and wakes up every n-th milliseconds. - Whenever the thread wakes-up, it gets the current frame/callstack for all the active threads (using threading.enumerate()) and increments an occurence counter for each currently executed code path. - When enough time has passed, all the collected samples are saved for analysis. This works somehow, but I fear this technique isn't aligned with how threading works in Python where only one thread can run Python code at a given time (GIL). Consider the following case: - An application has 2 threads running. - Thread A sleeps for 30 seconds. - Thread B does some heavy computation (only Python code). In this case, it is fairly obvious that most of the process execution time will be spent in thread B, which will likely have the GIL most of the time (since thread A is sleeping). However, when measuring the activity with the technique mentionned above, the sleep instruction in Thread B appears as the most costly code location, has it is present in every profiling sample. I'd like to modify my approach above by only measuring the activity of the last active thread. Obviously, this is not as simple as calling `threading.current_thread()` because it will always give me the profiling thread which is currently executing. Is there a way to know which thread had the GIL right before my profiling thread acquired it ? Perhaps through a C extension ? I've seen such profilers for Linux that take advantage of an ITIMER signal to do that. Sadly this is not an option on Windows. Any feedback or remark concerning my technique is also welcome. Thanks, Julien. -- https://mail.python.org/mailman/listinfo/python-list
Make synchronous generator from an asynchronous generator
Hello, I have recently got the need to convert a synchronous function to asynchronous function because I needed to run three of them concurrently. Since I am using Python 3.6, I used async def and asyncio and that has worked out great. Thank you guys for making this possible. Because I wanted to keep the synchronous function for scripts which used it, without unnecessarily duplicating the code, I built also a synchronous function from this new asynchronous one, like that: def acquire_to_files(self, *args, **kwargs): loop = asyncio.get_event_loop() loop.run_until_complete(self.acquire_to_files_async(*args, **kwargs)) loop.close() So far, it works fine. I am quite happy. I can await acquire_to_files_async in situations where I need concurrency, and call acquire_to_files in situations where I don't, and no code is duplicated. Now I wish to do the same game with a generator (which happens to be called by the acquire_to_files_async function). So I made it into an asynchronous generator, and it works as expected. My problem: how do I proceed if I wish to build a synchronous generator from this asynchronous generator ? (for situations where concurrency is not needed) i.e. what is the equivalent of the above snippet for generators ? Thanks, Julien PS: I was surprised however that enumerate does not work when applied to an asynchronous generator, i.e.: async for ii, img in enumerate(async_gen()): pass raises TypeError: 'async_gen' object is not iterable. -- https://mail.python.org/mailman/listinfo/python-list
Re: Make synchronous generator from an asynchronous generator
Le 16/03/2018 à 16:55, Ian Kelly a écrit : Note that this function can't be called more than once, because it closes the event loop at the end. Next time you call it it will get the closed event loop and try to schedule on it and then raise an exception because it's closed. Ah ok. So, if I replace get_event_loop() with new_event_loop(), then it's fine ? Well, it's not pretty, but this seems to work: [...] Thanks ! Julien -- https://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous processing is more efficient -- surely not?
Le 04/04/2018 à 09:27, Steven D'Aprano a écrit : Yes, this exactly. And if you're writing a web app, or certain kinds of desktop apps, these seems sensible. I don't want my browser to come to a complete halt just because some resource is taking a few seconds to respond. But honestly, from everything I've seen, outside of browser apps (and I'm not even sure about them), async processing looks to me like the wrong solution to, well, everything. For what it's worth, I can give you an example that I have been playing with lately, and it has nothing to do with browser app. I have been doing scientific image acquisition with Python for some time, and was quite happy with my program. But then, I suddently needed to fetch from several cameras at once, and also query another device at another interval. Of course, it is possible to do that in a simple loop without asyncio, but I thought I would give asyncio a try, and I was amazed at how easy it makes this kind of task. And then it is simple to remove/add a camera, etc. My only concern is that I tend to have code duplication between the async version of the program and the sync version of the program. In this case, the script spends most of its time waiting for a frame to be available on the cameras, and the time interval to query the other device. The fetching and processing of the frames take negligible time. The library that I use is not asynchronous, but it was very easy to run_in_executor the C function that blocks until a frame is available on a given camera. Compared to a non-async version where I would have had to use that C function with some short timeout and iterate over all cameras, I think the async version is more efficient. The await will just be as long as it takes for the WaitFrame C function to run... When the C function ends, the asynchronous task resumes... There is no need to adjust some timeout by hand. Bests, Julien -- https://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous processing is more efficient -- surely not?
Le 04/04/2018 à 14:45, Chris Angelico a écrit : Can you give an example? Let's say we have a simple blocking C function: int get_data() { sleep(2); return 42; } I am not saying that I understand 100% and that this is the best way, but it works for me: % cat get_data.c #include int get_data() { sleep(2); return 42; } % clang -shared -o libgetdata.dylib get_data.c % cat get_data_async.py import ctypes import asyncio mylib = ctypes.cdll.LoadLibrary('libgetdata.dylib') loop = asyncio.get_event_loop() async def get_data(): result = await loop.run_in_executor(None, mylib.get_data) print('C function returned', result) return result async def another_task(): for i in range(5): print(i) await asyncio.sleep(1) loop.run_until_complete(asyncio.gather(get_data(), another_task())) loop.close() % python get_data_async.py 0 1 C function returned 42 2 3 4 How do you use run_in_executor to turn this asynchronous, and how would this compare to creating one thread for each camera? This is exactely like creating a thread. Except that I have to do so only for blocking calls and without having to bother myself with threads or thread pools. AIUI, run_in_executor uses a thread pool under the surface, so all you're doing is using threads via an asyncio interface. Comparing to a timeout implementation is unfair; a threaded implementation is more comparable. Agreed. It is just that it looks very simple to me. But I have never really done any asynchronous programming before. So, maybe using threads is just as simple, I don't know. What I find nice with asyncio is that it integrates easily with already written Python code, i.e. converting synchronous code to asynchronous code is relatively straightforward. Again, my problem is that it leads to code duplication. But that probably means that I should separate the logic into separate functions more. Bests, Julien -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm wrong or Will we fix the ducks limp?
Antoon Pardon wrote: > A.x = 1; > A.y = 2; > > B = A; > > B.x = 3; > B.y = 4; > > > In C the variable A will still be x:1, y:2. > In Python the variable A will be x:3, y:4. But it would, if you had written instead: A->x = 1; A->y = 2; B = A; B->x = 3; B->y = 4; which backs indeed the C pointer analogy... -- Julien Salort Entia non sunt multiplicanda praeter necessitatem http://www.juliensalort.org -- https://mail.python.org/mailman/listinfo/python-list
Re: Bulk Adding Methods Pythonically
Ethan Furman wrote: > If that is all correct, then, as Random suggested, move that loop into > the class body and use locals() [1] to update the class dictionary. > Just make sure and delete any temporary variables.[ [...] > [1] https://docs.python.org/3/library/functions.html#locals > Yes, returning the class namespace is a language gaurantee. But that says: "Note The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter." -- Julien Salort Entia non sunt multiplicanda praeter necessitatem http://www.juliensalort.org -- https://mail.python.org/mailman/listinfo/python-list
Re: Why not allow empty code blocks?
Steven D'Aprano wrote: > It could be, but won't be. Outside of a very few tiny niches, including > Squeak which is designed for children, such user-interfaces are far too > cumbersome to ever get widespread use. Unfortunately, many people use LabView in my field... even for sufficiently complex programs for it to become totally unreadable. -- Julien Salort Entia non sunt multiplicanda praeter necessitatem http://www.juliensalort.org -- https://mail.python.org/mailman/listinfo/python-list
getting data off a CDrom
Hi there, I'm trying to load data from 2 different CD drives to compare the data on them to see if they are identical. I've found the WinCDRom module online but it doesn't seem to give access to the data at all. The only thing it seems to do is check if there is a readable cd in a specific drive. Any ideas/suggestions/flames? Thanks, Julien -- http://mail.python.org/mailman/listinfo/python-list
mod_python and Internal Server Error ...
Hello, I'm using mod_python 3.1.3 with Apache 2.0.54 on a Debian box with the publisher handler and the Clearsilver template engine, and from time to time apache returns an 500 error code (Internal Server Error). Apache errog.log file looks like : [Tue Jun 28 14:42:12 2005] [error] [client 164.x.x.x] PythonHandler mod_python.publisher: Traceback (most recent call last): [Tue Jun 28 14:42:12 2005] [error] [client 164.x.x.x] PythonHandler mod_python.publisher: File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\nresult = object(req) [Tue Jun 28 14:42:12 2005] [error] [client 164.x.x.x] PythonHandler mod_python.publisher: File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line 98, in handler\npath=[path]) [Tue Jun 28 14:42:12 2005] [error] [client 164.x.x.x] PythonHandler mod_python.publisher: File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 454, in import_module\nf, p, d = imp.find_module(parts[i], path) [Tue Jun 28 14:42:12 2005] [error] [client 164.x.x.x] PythonHandler mod_python.publisher: ImportError: No module named taxal ... What is strange is that when I reload the page, it's displayed fine, but from time to time I get 500 error code ... which is quite annoying ... As I'm using the publisher handler, my index.py looks like : import sys import os.path import neo_cgi import neo_util import neo_cs from mod_python import util, apache from psycopg import QuotedString config = apache.import_module('config', autoreload = 0, log = 0) utils = apache.import_module('utils', autoreload = 0, log = 0) specimen = apache.import_module('specimen', autoreload = 0, log = 0) taxon = apache.import_module('taxon', autoreload = 0, log = 0) fulltextsearch = apache.import_module('fulltextsearch', autoreload = 0, log = 0) template_directory = config.getTemplateDirectory() template_main = config.getTemplateMain() template_menu = config.getTemplateMenu() def index(req): return home(req) def home(req): return _render(req, 'home') def links(req): return _render(req, 'links') def contact(req): return _render(req, 'contact') def taxal(req): sort= req.form.getfirst('sort') order = req.form.getfirst('order') tl = taxon.taxon() tl.getTaxaList(sort, order) hdf = tl.getHDF() return _render(req, 'taxalist', hdf) (...) So for the above example if I GET http://b.abc.be/birds/taxal it should run the "def taxal(req)" function ... I don't understand why I get a "mod_python.publisher: ImportError: No module named taxal" error message in the apache logfile. We have several virtualhosts : a.abc.be, b.abc.be, c.abc.be, ... (fictive addresses). Our www directory is organized like this : /var/www/vhosts/a.abc.be/ /var/www/vhosts/b.abc.be/ /var/www/vhosts/b.abc.be/enbi/ /var/www/vhosts/b.abc.be/enbi/projects/birds/ /var/www/vhosts/b.abc.be/enbi/projects/butterfly/ /var/www/vhosts/b.abc.be/enbi/projects/rubiaceae/ /var/www/vhosts/c.abc.be/blah/ I've tried with "PythonInterpPerDirectory on" in my .htaccess, but without success ... In advance thanks for your support -- http://mail.python.org/mailman/listinfo/python-list
Re: [code-quality] [ANN] Pylint 1.4 released
On Thu, Nov 27, 2014 at 10:19:28 -0500, Ned Batchelder wrote: > I found a problem with the new spell feature, but the issue tracker > (http://www.bytebucket.org/logilab/pylint/issues) seems broken: > everything I tried ended at a 403 CSRF validation failure page. > Not sure where that url came from, afaik the tracker is https://bitbucket.org/logilab/pylint/issues Cheers, Julien -- Julien Cristau Logilab http://www.logilab.fr/ Informatique scientifique & gestion de connaissances -- https://mail.python.org/mailman/listinfo/python-list
PythonMagick on Windows DLL load failed
I am using Python 2.7 on Windows 8.1. Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32 I installed ImageMagick from imagemagick.org <http://www.imagemagick.org/script/binary-releases.php#windows> Then installed PythonMagick with pip from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonmagick When I import PythonMagick it says: Traceback (most recent call last): File "magic.py", line 2, in import PythonMagick File "C:\Python27\lib\site-packages\PythonMagick\__init__.py", line 1, in from . import _PythonMagick ImportError: DLL load failed: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. Any clues on where do look? Question on stackoverflow http://stackoverflow.com/questions/28538973/pythonmagick-on-windows-dll-load-failed -- Julien Levasseur -- https://mail.python.org/mailman/listinfo/python-list
list of indices
hi,is there any method to get only some elements of a list from a list of indices. Something like:indices=[0,3,6]new_list=list[indices]which would create a new list containing 0th, 3rd and 6th elements from the original list? I do this with a loop but I'd like to know if there is a simpler way.thanks in advanceJul-- http://mail.python.org/mailman/listinfo/python-list
web searching scripts
Does anyone know of a freely available script that can take a given URL and follow every link within it? Ideally, I would like to start with this to build a quick application to grab all the content off a website to publish it to a CD. Thanks, jul -- http://mail.python.org/mailman/listinfo/python-list
dbm
Hello list, I have a dbm "database" which needs to be accessed/writed by multiple processes. At the moment I do something like : @with_lock def _save(self): f = shelve.open(self.session_file, 'c') try: f[self.sid] = self.data finally: f.close() the with_lock() decorator create a .lock file which is deleted when the function exit, so every operation did the following: - acquire .lock file - open the dbm file - do the operation (save, load, ...) - close the dbm file - delete the .lock file I made some tests and following my results the open() / close() add some overhead (about 5 times slower). I read that the gdbm module should be safe against multiple processes (I saw the "'u' -- Do not lock database." in the doc, so I presume it's locked by default ?). Does it mean that two (or more) processes can open the dbm file and write in the same time without errors/corruptions/segfaults/... ? Thanks, Julien -- http://mail.python.org/mailman/listinfo/python-list
Pyrex installation on windows XP: step-by-step guide
Do you wand to install Pyrex on Windows ? Here is a step-by-step guide explaining: A) how to install Pyrex on Windows XP. B) how to compile a Pyrex module. Julien Fiore, U. of Geneva --- ### A) Pyrex installation on Windows XP ### # step A.1 # Install Python (we used version 2.4.2) # step A.2 # Run the windows installer for Pyrex (e.g. Pyrex-0.9.3.1.win32.exe), available on the Pyrex homepage (http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/) # step A.3 # Install Mingw, the gcc compiler for Windows, available at http://www.mingw.org/download.shtml. (we downloaded the file MinGW-5.0.2.exe and installed only the "base tool" (this includes mingw-runtime 3.9, w32api-3.6, binutils 2.15.91 and gcc-core 3.4.2). Add Mingw path ("C:\MinGW\bin") to the Windows "Path" environment variable. If you already have cygwin installed, add C:\MinGW\bin before the Cygwin path. # step A.4 # Create or edit the file "c:/Python2x/Lib/distutils/distutils.cfg" and put the following into it: [build] compiler = mingw32 --- ### B) Create a Pyrex module ### # step B.1 # Create a working directory (e.g. D:\pyrex_module\). Write a pyrex module and save it with a "pyx" extension (e.g. "primes.pyx", code available on the Pyrex homepage) # step B.2 # Write the following python script and save it as "setup.py" in your working directory. from distutils.core import setup from distutils.extension import Extension from Pyrex.Distutils import build_ext setup( name = "PyrexGuide", ext_modules=[ Extension("primes", ["primes.pyx"]) ], cmdclass = {'build_ext': build_ext} ) If you want to compile several modules, duplicate the line starting with "Extension" and replace "primes" by your module names. # step B.3 # In your working directory, create a batch file called "build_and_install.bat" containing the following lines, where "PythonXX" should be replaces by your Python version (e.g. "Python24"). C:\Python24\python.exe setup.py build_ext install pause To run the batch, double-click the file. You will see many "Warning" messages during the building process: do not worry, it is normal. # step B.4 # Mission completed. The file "primes.pyd" (a "pyd" is a Python Extension DLL, equivalent of .so in Unix) is now located in "C:\Python24\Lib\site-packages" and the "primes" module is available in Python. In your working directory, you can delete the file "primes.c" and the "build" folder created by the building process. Test your new module at the python shell: >>> import primes >>> primes.primes(10) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] -- http://mail.python.org/mailman/listinfo/python-list
problems installling scipy.weave on windows
Hi, I have problems trying to install the scipy.weave package. I run Python 2.4 on windows XP and my C compiler is MinGW. Below is the output of scipy.weave.test(). I read that the tests should last several minutes, but in my case it only lasts a few seconds. Thanks in advance for any help. Julien Fiore >>> import scipy.weave >>> scipy.weave.test() Found 16 tests for scipy.weave.slice_handler Found 0 tests for scipy.weave.c_spec Found 2 tests for scipy.weave.blitz_tools building extensions here: c:\docume~1\julien~1\locals~1\temp\Julien\python24_compiled\m10 Found 1 tests for scipy.weave.ext_tools Found 74 tests for scipy.weave.size_check Found 9 tests for scipy.weave.build_tools Found 0 tests for scipy.weave.inline_tools Found 1 tests for scipy.weave.ast_tools Found 0 tests for scipy.weave.wx_spec Found 3 tests for scipy.weave.standard_array_spec Found 26 tests for scipy.weave.catalog Found 0 tests for __main__ ...EE..E..EEEE...warning: specified build_dir '_bad_path_' does not exist or is not writable. Trying default locations .warning: specified build_dir '_bad_path_' does not exist or is not writable. Trying default locations ....removing 'c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test' (and everything under it) error removing c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test: c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test\win3224compiled_catalog: Permission denied error removing c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test: c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test: Directory not empty .removing 'c:\docume~1\julien~1\locals~1\temp\tmpt-_vddcat_test' (and everything under it) . == ERROR: check_error1 (scipy.weave.size_check.test_size_check.test_dummy_array) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 99, in check_error1 self.generic_error_test(x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 134, in generic_error_test self.generic_test('',x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 131, in generic_test self.assert_array_equal('',actual,desired) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 110, in assert_array_equal assert(actual == desired) File "C:\Python24\lib\site-packages\scipy\weave\size_check.py", line 122, in __cmp__ if len(self.shape) == len(other.shape) == 0: AttributeError: 'tuple' object has no attribute 'shape' == ERROR: check_error2 (scipy.weave.size_check.test_size_check.test_dummy_array) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 102, in check_error2 self.generic_error_test(x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 134, in generic_error_test self.generic_test('',x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 131, in generic_test self.assert_array_equal('',actual,desired) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 110, in assert_array_equal assert(actual == desired) File "C:\Python24\lib\site-packages\scipy\weave\size_check.py", line 122, in __cmp__ if len(self.shape) == len(other.shape) == 0: AttributeError: 'tuple' object has no attribute 'shape' == ERROR: check_1d_3 (scipy.weave.size_check.test_size_check.test_dummy_array_indexing) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 207, in check_1d_3 if nx.which[0] != "numarray": AttributeError: 'module' object has no attribute 'which' == ERROR: check_1d_6 (scipy.weave.size_check.test_size_check.test_dummy_array_indexing) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 214, in check_1d_6 if nx.which[0] != "numarray": AttributeError: 'module' object
Re: Pyrex installation on windows XP: step-by-step guide
To install Pyton, I simply used the python Windows installer (python-2.4.2.msi) available at python.org. Julien -- http://mail.python.org/mailman/listinfo/python-list
Read and extract text from pdf
Hi, I have a problem :), I just want to extract text from pdf file with python. There is differents libraries for that but it doesn't work... pyPdf and pdfTools, I don't know why but it doesn't works with some pdf... For example space chars are delete in the text.. Pdf playground : I don't understand how it work. If you have an idea, a tutorial, a library or anything who can help me to do that. -- http://mail.python.org/mailman/listinfo/python-list
Read and extract text from pdf
Hi, Thanks I use that and is all right :) import commands txt = commands.getoutput('ps2ascii tmp.pdf') print txt -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
Thanks for your remark, Sturlamolden. Is there a free version of the "Visual C++ 2003" compiler available on the web? I have found "Visual C++ 2005 Express edition" (http://msdn.microsoft.com/vstudio/express/visualc/). According to Micrsoft, it replaces VC++2003 (http://msdn.microsoft.com/visualc/vctoolkit2003/). Is VC++2005ee the good compiler to compile a Pyrex module (or any Python extension) ? Does it link with msvcr71.dll ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
sturlamolden wrote: > edit the text file "c:\mingw\lib\gcc\mingw32\3.2.4\specs" > and change "-lmsvcrt" to "-lmsvcr71". Thank you very much sturlamolden, This procedure should be added to the "step-by-step" guide (see 1st message of this thread) as "step A.5". For ignorant people like me, CRT = "C runtime library". -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
I added "step A.5" to the guide and published it on the Python wiki, so that anyone can update it easily: http://wiki.python.org/moin/PyrexOnWindows -- http://mail.python.org/mailman/listinfo/python-list
Python sqlite and regex.
Hi, I'd like to use regular expressions in sqlite query, I using apsw module but it doesn't work...Can you help me ? My script: import apsw import re path = 'db/db.db3' #regexp function (extract from python-list discusion) def regexp(expr, item): reg = re.compile(expr) return reg.match(item) is not None con = apsw.Connection(path) #create function con.createscalarfunction("REGEXP", regexp) cur = con.cursor() #exampl cur.execute("select foo from test where foo regex 'aa.[0-9])") and the error is: cur.execute('select foo from test where foo regex tata') apsw.SQLError: SQLError: near "regex": syntax error Thanks -- http://mail.python.org/mailman/listinfo/python-list
Use of Python with GDAL. How to speed up ?
Hi, I wrote a function to compute openness (a digital elevation model attribute). The function opens the gdal-compatible input raster and reads the values in a square window around each cell. The results are stored in a "1 line buffer". At the end of the line, the buffer is written to the output raster. It runs very slowly and I suspect the raster access to be the main bottleneck. Do you have any idea to speed-up the process ? Thanks for any help. Julien Here is the code: # ## openness.py ## ## Julien Fiore, UNIGE ## ## code inspired by Matthew Perry's "slope.cpp" # import import numpy import gdal from gdal.gdalconst import * # for GA_ReadOnly in gdal.gdal.Open() def openness(infile, outfile, R=1): """ Calculates the openness of a gdal-supported raster DEM. Returns nothing. Parameters: infile: input file (georeferenced raster) outfile: output file (GeoTIF) R: opennness radius (in cells). Window size = (2*R + 1)**2 """ # open inGrid try: inGrid = gdal.gdal.Open(infile, GA_ReadOnly ) except IOError: print 'could not open inGrid' inGridBand = inGrid.GetRasterBand(1) # get raster band # get inGrid parameters geoTrans = inGrid.GetGeoTransform() # returns list (xOrigin,xcellsize,...) cellSizeX = geoTrans[1] cellSizeY = geoTrans[5] nXSize = inGrid.RasterXSize nYSize = inGrid.RasterYSize nullValue = inGridBand.GetNoDataValue() # Create openness output file format = "GTiff" driver = gdal.gdal.GetDriverByName( format ) outGrid=driver.CreateCopy(outfile,inGrid) # Creates output raster with # same properties as input outGridBand = outGrid.GetRasterBand(1) # Access Band 1 outGridBand.SetNoDataValue(nullValue) # moving window winSize= 2*R + 1 # openness buffer array (1 line) buff = inGridBand.ReadAsArray(xoff=0, yoff=0, win_xsize=nXSize, win_ysize=1) # create distance array for Openness dist=numpy.zeros((winSize,winSize),float) for i in range(winSize): for j in range(winSize): dist[i][j]=numpy.sqrt((cellSizeX*(i-R))**2 + (cellSizeY*(j-R))**2) # openness loop for i in range(nYSize): for j in range(nXSize): containsNull = 0 # excludes the edges if (i <= (R-1) or j <= (R-1) or i >= (nYSize-R) or j >= (nXSize-R) ): buff[0][j] = nullValue continue # continues with loop next iteration # read window win = inGridBand.ReadAsArray(j-R, i-R, winSize, winSize) # Check if window has null value for value in numpy.ravel(win): if value == nullValue : containsNull = 1 break # breaks out of the smallest enclosing loop if (containsNull == 1): # write Null value to buffer buff[0][j] = nullValue continue # continues with loop next iteration else: # openness calculation with "tan=opp/adj" # East E=180.0 # 180 = max angle possible between nadir and horizon for k in range(R+1,2*R): angle= 90.0 - numpy.arctan((win[k][R]-win[R][R])/dist[k][R]) if anglehttp://mail.python.org/mailman/listinfo/python-list
Re: Use of Python with GDAL. How to speed up ?
Thanks for the psyco information, Serge. > 2) Rewrite the code to be vectorized (don't use psyco) Right now your > code *doesn't* get any speed benefit from numpy I do not understand this point. How to rewrite the code ? Do you mean in C ? Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Python with GDAL. How to speed up ?
Thanks Caleb for the advice, I profiled my code with the following lines: import profile, pstats profile.runctx('openness(infile,outfile,R)',globals(),locals(),'profile.log') p = pstats.Stats('profile.log') p.sort_stats('time') p.print_stats(10) The outputs tells me that the openness() function takes most of the time. This is not very useful for me, as openness() contains most of my code. How to know which instructions take most time in the openness function ? Do I have to separate the code into smaller functions ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Python with GDAL. How to speed up ?
Thank you Serge for this generous reply, Vectorized code seems a great choice to compute the distance. If I understand well, vectorized code can only work when you don't need to access the values of the array, but only need to know the indices. This works well for the distance, but I need to access the array values in the openness function. As regards array.array, it seems a bit complicated to reduce all my 2D arrays to 1D arrays because I am working with the gdal library, which works only with 'numeric' arrays. Julien -- http://mail.python.org/mailman/listinfo/python-list
Using PyImport_ExtendInittab with package
Hi, I'm trying to embed Python and therefore use PyImport_ExtendInittab() to register modules. My current problem is that, if it works well with a simple module "hello", naming a module "hello.foobar" in the inittab struct does not seems to work. imp.find_module("hello.foobar") returns correctly that the module is found, but import hello.foobar fails badly. Is . notation supported in inittab? Am I doing something wrong? -- Julien Danjou // ᐰhttp://julien.danjou.info // 9A0D 5FD9 EB42 22F6 8974 C95C A462 B51E C2FE E5CD // Don't give up. signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Python 2.7, tkinter problem on OSX
Dear list, Last version of my software relies on ttk. Under windows and linux this is fine. But, OSX users are facing problems (I don't have access to a Mac myself for testing...). Those with OSX 10.6 can run the program. It seems that OSX 8.6 ships with Tk8.5. People with OSX 8.5 cannot run the app. I told them to install python 2.7 which seems to be the first version on OSX to ship with Tk8.5. However, the program still does not run. I asked a person to launch a python 2.7 interpreter and try to import tkinter. This is an excerpt of the output: from Tkinter import * File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so: no matching architecture in universal wrapper Full log is there: http://pastebin.com/vky8FbrP I asked a person to simply open a python2.7 shell and import Tkinter. He got the same error. All of this is executed with Python 2.7rc1. Archives that are on the ftp of python.org. I have seen this bug http://bugs.python.org/issue9045, which is related, but deals with the specificities if OSX 64bit. Can this problem be solved by installing Active TK 8.5 for OSX ? Anybody knows what is the good combination of installer / libraries to install to run a ttk application on OSX 8.5 ? Ideally, I would like to document the setup procedure for 8.5 users. Cheers, Julien -- http://mail.python.org/mailman/listinfo/python-list
Random and fork
Hi everyone, Today I came accross a behaviour I did not expect in python (I am using 2.7). In my program, random.random() always seemed to return the same number; it turned out to be related to the fact that I was using os.fork. See below a small program that illustrates this. It is easily fixed, but I'm interested in knowing why this happens. Can anybody give me a hint? Thanks! import random import os for i in xrange(10): pid = os.fork() if pid == 0: # uncommenting this fixes the problem # random.seed(os.getpid()) print random.random() os._exit(0) os.wait() -- http://mail.python.org/mailman/listinfo/python-list
Re: Random and fork
Thank you for the answers! It was much simpler than I thought. On Wednesday, 6 February 2013 17:49:06 UTC+1, Alain Ketterlin wrote: > Julien Le Goff writes: > > > > > Today I came accross a behaviour I did not expect in python (I am > > > using 2.7). In my program, random.random() always seemed to return the > > > same number; it turned out to be related to the fact that I was using > > > os.fork. > > > > The random number generator is initialized once, when the module is > > first imported. Forking simply duplicates the process in its current > > state, so no reinitilization occurs, both (or all) processes' generators > > are in the same state, and therefore generate the same sequence. > > > > -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Subprocess Startup Error
Whenever I try to open the python shell it says IDLE’s subprocess didn’t make a connection. Everything worked fine yesterday and I haven’t done anything I think would cause this problem. Any way to fix this? I’ve tried repairing and redownloading -- https://mail.python.org/mailman/listinfo/python-list
Python 3.6
How do i open python 3.6 in a console and how do i see the binary its running with -- https://mail.python.org/mailman/listinfo/python-list
Console
I had an problem when trying to start the python GUI. It said there was a subprocess startup error. I was told to start IDLE in a console with idlelib and see what python binary i was runnning IDLE with. Im using windows 10 and i guess console refers to the terminal window and i have no idea what they meant by "the binary its running with" -- https://mail.python.org/mailman/listinfo/python-list
Re: Console
I think i fixed the problem for now. When i tried to run programs it was giving me errors in certain prewritten python files so i wiped them all and redownloaded them from the website - Original Message - From: "Rhodri James" To: python-list@python.org Sent: Wednesday, March 7, 2018 8:55:30 AM Subject: Re: Console On 07/03/18 14:41, Jeremy Jamar St. Julien wrote: > I had an problem when trying to start the python GUI. It said there was a > subprocess startup error. I was told to start IDLE in a console with idlelib > and see what python binary i was runnning IDLE with. Im using windows 10 and > i guess console refers to the terminal window and i have no idea what they > meant by "the binary its running with" > I'm afraid I can't help you with with the Console program. Windows does like to bury Console deep in its menus, and I don't have a copy of Windows 10 to find it in. Once you have a console running, all you should need to do then is type "idle" at the prompt. That should open a window, which amongst other things will tell you the version of Python it is using. If that fails, try "idle -n" instead; it may not make any difference, but it's worth a go. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list