Re: Odd msg received from list
On Thu, Nov 14, 2013 at 2:53 PM, Verde Denim tdl...@gmail.com wrote: Has anyone else received a message like this? I did too. It seems to me that Gmail's spam filter might have been overly enthusiastic, but the only way to find out is to look at the bounces that the list software received. Yesterday I also received a warning from the debian-laptop mailing list program. Joost -- https://mail.python.org/mailman/listinfo/python-list
Re: How to streamingly read text file and display whenever updated text
A bit of googling found me this: http://www.linux-support.com/cms/implementation-of-tail-in-python/ import time import sys def tail_f(file): interval = 1.0 while True: where = file.tell() line = file.readline() if not line: time.sleep(interval) file.seek(where) else: yield line -- https://mail.python.org/mailman/listinfo/python-list
Re: extraction tool using CRF++
Hi Ron, In the python/ subdirectory of the CRF++ source package there's a README with instructions on how to use the CRFPP python module. HTH, Joost On Tue, Oct 1, 2013 at 4:24 PM, Vlastimil Brom vlastimil.b...@gmail.com wrote: 2013/10/1 cerr ron.egg...@gmail.com: Hi, I want to write an extraction tool using CRF++ (http://crfpp.googlecode.com/svn/trunk/doc/index.html). I have written a trainings file and a template: training: banana FOODB-NP bread FOODI-NP template: U01:%x[0,1] U02:%x[1,1] and now I want to go ahead and extract the foods from a sentence like how do I make a banana bread. Also, I'm unsure how I interface to crf++ with python, I compiled and installed it from source as described on the above website but I don't have a crf module available in python... -- https://mail.python.org/mailman/listinfo/python-list Hi, I have unfortunately no experience with CRF++; if there is no python wrapper for it available, the usage might not be (easily) possible - depending on the character of this library, you may try accessing it e.g. via ctypes. Alternatively, you may try another packages already available, e.g. NLTK: http://nltk.org/ import nltk any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(apple)) True any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(bread)) True any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(wine)) True any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(book)) False any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(pencil)) False # of course there might be some surprise, probably due to polysemy ore some specifics of the semantic description... any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(dog)) True any(synset.lexname == noun.food for synset in nltk.corpus.wordnet.synsets(white)) True cf. http://nltk.org/ http://nltk.googlecode.com/svn/trunk/doc/howto/wordnet.html http://www.velvetcache.org/2010/03/01/looking-up-words-in-a-dictionary-using-python http://wordnet.princeton.edu/man/lexnames.5WN.html hth, vbr -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
Look, i want this to stop. Open your own thread and discuss this if you like. This is a thread i opened for a specific question and all i see its irrelevant answers. Hi Ferrous, The problem is not in your Python code. You can debug it from the command line by typing the 'echo ... | mailx' command your Python code is executing. Somewhere on your local SMTP or on Google's SMTP, your message is not being processed the way you want it. There are many things that could cause this -- SPF, DKIM, reverse DNS not being correct, the From address being 'faked', or one of about a hunderd other factors. It's most likely an issue in your local SMTP server's configuration. You'll have to dive into the logs and do some research on how SMTP works nowadays to find out what's happening. But think about this: if I could send mail as nikos.gr...@gmail.com, just by typing a shell command, how could we ever trust e-mail to be from who it really is? What if I send mail as barack.ob...@whitehouse.gov? What you're doing may look like spam from Google's point of view, and that's why I think you're not receiving the message. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
Since the From address is random, it most likely doesn't exist, which could be reason for Google's smtp server to reject the message or to deliver it to spam. Also, the reverse DNS for 84.200.17.58 does not resolve to secure.superhost.gr, which could also be reason to reject the message. On Sun, Sep 15, 2013 at 5:54 PM, Ferrous Cranus nikos.gr...@gmail.com wrote: try: # prepare mail data FROM = random_char(10) + '@' + random_char(10) + '.com' TO = nikos.gr...@gmail.com SUBJECT = random_char( 50 ) MESSAGE = random_char( 500 ) os.system( echo %s | mailx -v -r %s -s %s %s % (MESSAGE, FROM, SUBJECT, TO) ) print( h2font color=blue%sη αποστολή προς %s επετεύχθη!/font/h2 % (times, TO) ) except Exception as e: print( sendmail = , date, repr( sys.exc_info() ) ) sys.exit(0) I'am still trying to send successfulyl a mail through my local host by using the local MTA, trying to avoid using GMail's SMTP server but the mail never gets send this is the error message: [code] ni...@superhost.gr [~/www/cgi-bin]# python mail.py LOG: MAIN cwd=/home/nikos/public_html/cgi-bin 6 args: send-mail -i -v -r zyn1kgs...@jrv0cei7tx.com nikos.gr...@gmail.com LOG: MAIN = zyn1kgs...@jrv0cei7tx.com U=nikos P=local S=1052 id=5235d7f5.bzp0tuy4zqeop7dh%zyn1kgs...@jrv0cei7tx.com T=QOU0ULMZBF7RGG7B260YERPPXXLTVQ9WKJ93ZXYABQNNA0XB9I Content-type: text/html; charset=utf-8 h2font color=blue0η αποστολή προς nikos.gr...@gmail.com επετεύχθη!/font/h2 LOG: MAIN cwd=/var/spool/exim 4 args: /usr/sbin/exim -v -Mc 1VLEdZ-0001Xg-6b delivering 1VLEdZ-0001Xg-6b ni...@superhost.gr [~/www/cgi-bin]# LOG: MAIN SMTP connection outbound 1379260405 1VLEdZ-0001Xg-6b superhost.gr nikos.gr...@gmail.com Connecting to gmail-smtp-in.l.google.com [173.194.70.26]:25 ... connected SMTP 220 mx.google.com ESMTP e49si15825947eep.141 - gsmtp SMTP EHLO secure.superhost.gr SMTP 250-mx.google.com at your service, [84.200.17.58] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 CHUNKING SMTP STARTTLS SMTP 220 2.0.0 Ready to start TLS SMTP EHLO secure.superhost.gr SMTP 250-mx.google.com at your service, [84.200.17.58] 250-SIZE 35882577 250-8BITMIME 250-ENHANCEDSTATUSCODES 250 CHUNKING SMTP MAIL FROM:zyn1kgs...@jrv0cei7tx.com SIZE=2090 SMTP 250 2.1.0 OK e49si15825947eep.141 - gsmtp SMTP RCPT TO:nikos.gr...@gmail.com SMTP 250 2.1.5 OK e49si15825947eep.141 - gsmtp SMTP DATA SMTP 354 Go ahead e49si15825947eep.141 - gsmtp SMTP writing message and terminating . SMTP 250 2.0.0 OK 1379260407 e49si15825947eep.141 - gsmtp SMTP QUIT LOG: MAIN = nikos.gr...@gmail.com R=lookuphost T=remote_smtp H=gmail-smtp-in.l.google.com [173.194.70.26] X=TLSv1:RC4-SHA:128 LOG: MAIN Completed [/code] Since all looks okey why the mail never gets delivered? -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Python TUI that will work on DOS/Windows and Unix/Linux
Have you looked at Blessings? I never tried it, but the API seems much cleaner than Curses. https://pypi.python.org/pypi/blessings/ -- Joost Molenaar -- https://mail.python.org/mailman/listinfo/python-list
Splitting large packages with distutils
Hello list, suppose I have three packages like this: ingredients-base/ ingredients/ __init__.py setup.py -- this one only references package ingredients ingredients-spam/ ingredients/ __init__.py spam/ __init__.py recipe.py setup.py -- this one only references package ingredients.spam ingredients-eggs/ ingredients/ __init__.py eggs/ __init__.py recipe.py setup.py -- this one only references package ingredients.eggs Now I can install these like this: virtualenv env env/bin/pip install file:///path/to/ingredients-base env/bin/pip install file:///path/to/ingredients-spam env/bin/pip install file:///path/to/ingredients-eggs Now I have one source tree with the packages ingredients, ingredients.spam and ingredients.eggs all rolled into one, so that works OK. But when I run pip uninstall for ingredients.spam, it also removes the source files for ingredients and ingredients.eggs. That seems a bit wrong, but maybe I'm using distutils/pip/setuptools the wrong way. I found out that if I modify top_level.txt in each of the egg-info directories that are installed so that they include the full package name, pip doesn't uninstall all the code. (And I didn't see any bad effects on the sys.path.) But I haven't found a non-hackish way to make top_level.txt contain the 'right' package name, so I think I'm not supposed to touch it, or even know that it's there. I wasn't able to find much documentation on this top_level.txt file, but what I found suggested that it's used for run-time conflict resolution, not for package management. [1] So my question is, how to make this scenario work? Just use different top-level package names and install them side-by-side? Looking at big projects such as Zope, Django or Twisted, they all seem to have gone the non-distutils route. Before anyone asks why I want this; I want to split up some framework-type code and some utility-type code I have from some application-specific code, and I hope that this way I'll be able to accurately specify and install the dependencies between projects without running ever more risk of clashing with a top-level module name. But I'm open to the suggestion that my idea is totally misguided. :-) Salutation, Joost Molenaar [1] http://svn.python.org/projects/sandbox/trunk/setuptools/doc/formats.txt -- http://mail.python.org/mailman/listinfo/python-list
Re: utcnow
Time zones! So much fun. Looks like you're dealing with UTC offsets yourself, which gets messy as soon as you start thinking about DST. The good news is that there's a timezone database on most systems, which you should almost definitely use. Take a look at python-dateutil (pip install python-dateutil): from datetime import datetime from dateutil import tz datetime.now() datetime.datetime(2012, 9, 17, 6, 33, 57, 158555) This is a so-called naive datetime, it doesn't know about timezones. On my system, it returns a time in my local time zone. (It could have been GMT or something else entirely.) You have to call .replace() on a naive datetime to set the tzinfo member to make it a timezone-aware datetime object: AMS = tz.gettz('Europe/Amsterdam') ATH = tz.gettz('Europe/Athens') datetime.now().replace(tzinfo=AMS).astimezone(ATH) datetime.datetime(2012, 9, 17, 7, 37, 38, 573223, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Athens')) Voila, it seems like you're one hour ahead of me. :-) HTH, Joost On 17 September 2012 06:25, Nick the Gr33k nikos.gr...@gmail.com wrote: Hello is there a better way of writing this: date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3) ).strftime( '%y-%m-%d %H:%M:%S') something like: date = datetime.datetime.utcnow(**hours=3).strftime( '%y-%m-%d %H:%M:%S') i prefer it if it could be written as this. Also what about dayligh savings time? -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse/argparse for cgi/wsgi?
Many people have. :-) In the context of WSGI you're basically talking about routing middleware, which solves the problem: given a request, which application should be called to construct a response? In my case, it turned out as simple as a list of (regex, resource) tuples, where regex is a regular expression that looks at the request URI and resource is an object that may or may not implement GET, POST, PUT, DELETE methods. In the regex I can capture any arguments that the resource needs. If the request method is GET and the method GET exists on the matched resource, it is called, else a 'Method Not Allowed' response code is returned. HTH Joost On 10 December 2010 17:36, samwyse samw...@gmail.com wrote: Has anyone ever built some sort of optparse/argparse module for cgi/ wsgi programs? I can see why a straight port wouldn't work, but a module that can organize parameter handling for web pages seems like a good idea, especially if it provided a standard collection of both client- and server-side validation processes, easy internationalization, and a way to create customizable help pages. -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse/argparse for cgi/wsgi?
To aid your googling, the problem is also commonly called 'Dispatching' instead of 'Routing'. Joost On 14 December 2010 12:19, Joost Molenaar j.j.molen...@gmail.com wrote: Many people have. :-) In the context of WSGI you're basically talking about routing middleware, which solves the problem: given a request, which application should be called to construct a response? In my case, it turned out as simple as a list of (regex, resource) tuples, where regex is a regular expression that looks at the request URI and resource is an object that may or may not implement GET, POST, PUT, DELETE methods. In the regex I can capture any arguments that the resource needs. If the request method is GET and the method GET exists on the matched resource, it is called, else a 'Method Not Allowed' response code is returned. HTH Joost On 10 December 2010 17:36, samwyse samw...@gmail.com wrote: Has anyone ever built some sort of optparse/argparse module for cgi/ wsgi programs? I can see why a straight port wouldn't work, but a module that can organize parameter handling for web pages seems like a good idea, especially if it provided a standard collection of both client- and server-side validation processes, easy internationalization, and a way to create customizable help pages. -- Joost Molenaar +31 644 015 510 -- http://mail.python.org/mailman/listinfo/python-list
Descriptors and decorators
WebOb contains this little nugget of code that allows you to define a decorator that works on both methods and functions: class Decorator(object): def __init__(self, func): self.func = func def __get__(self, object, type=None): if type is None: return self newfunc = self.func.__get__(object, type) return self.__class__(newfunc) I adapted it into a class, so that I can inherit this functionality without thinking about it: class trace(Decorator): def __call__(self, *a, **kw): print '--', self.func.__name__, repr(a), repr(kw) result = self.func(*a, **kw) print '--', self.func.__name__, '=', repr(result) return result I can then use it like this: class C(object): @trace def m(self, x): return 2 * x And like this: @trace def f(x): return 2 * x It works: o = C() o.m(21) -- m (21,) {} -- m = 42 f(21) -- f (21,) {} -- f = 42 I'm still not sure what Decorator.__get__ does, or at least I'm not sure enough to be able to explain it well. Logically, the method C.m is unbound at the time the class is defined but o.m is bound when it is called. This means that what Decorator.__init__ receives as its 'func' parameter is the unbound method C.m, and when it runs it should operate on the bound method o.m instead. I suspect that this is what happens inside Decorator.__get__: create a new instance of the decorator, with a bound version of the decorated method, and call that without needing a 'self' parameter. Is this in fact the easiest way to explain it? Joost Molenaar -- http://mail.python.org/mailman/listinfo/python-list
Re: Descriptors and decorators
On 25 October 2010 15:20, bruno.desthuilli...@gmail.com bruno.desthuilli...@gmail.com wrote: So, your decorator is applied to a function, and wraps it into a Decorator object. Or more exactly, the function is defined, then the Decorator class is called so a new Decorator object is instanciated with the function as argument, and finally this Decorator instance is rebound to the name under which the function was formely known. All this happenning _before_ class C even exists, so when the class object is created, it has an attribute by the name of the decorated function which is in fact a Decorator instance. Now this instance is itself a descriptor, so when C.m or o.m are looked up, the descriptor protocol is fired and Descriptor.__get__ is called. If called without at least a 'type' argument, it just returns itself, so it works as an ordinary function. Else it calls the function's own descriptor implementation to get a bound or unbound method, and returns a new instance of the decorator with the method as argument. Thanks, Bruno. Your python-wiki page and walk-through for the Decorator code make it clear. I now finally understand that methods are in fact ordinary functions at the time the class is created, and that the descriptor protocol turns them into bound or unbound methods when they're accessed as attributes: class K(object): pass ... def g(self): pass ... g function g at 0x7f322f701838 K.m = g K.m unbound method K.g K.__dict__['m'] function g at 0x7f322f701838 K().m bound method K.g of __main__.K object at 0x7f322f709a50 Cheers! Now I will try to wrap my brain around metaclasses and coroutines. ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to scrutch a dict()
Using a 2.7/3.x dictionary comprehension, since you don't seem to mind creating a new dictionary: def _scrunched(d): return { key: value for (key, value) in d.items() if value is not None } Joost On 21 October 2010 06:32, Phlip phlip2...@gmail.com wrote: Not Hyp: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? Python does so often manage maps better than that... -- Phlip http://zeekland.zeroplayer.com/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: if the else short form
Hi Nico, it's converting fill==True to an int, thereby choosing the string False, or True, by indexing into the tuple. Try this in an interpreter: ['a','b'][False] 'a' ['a','b'][True] 'b' int(False) 0 int(True) 1 Joost On 29 September 2010 12:42, Tracubik affdfsdfds...@b.com wrote: Hi all, I'm studying PyGTK tutorial and i've found this strange form: button = gtk.Button((False,, True,)[fill==True]) the label of button is True if fill==True, is False otherwise. i have googled for this form but i haven't found nothing, so can any of you pass me any reference/link to this particular if/then/else form? thanks Nico -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: FM synthesis using Numpy
Thanks/bedankt Bas for the educative reply. I think I got misleaded by Max/MSP's tutorial[1], because MSP seems to automatically adjust the phase when you combine two oscillators in the way that I did. Joost [1] page 112 of http://www.cycling74.com/download/MSP45TutorialsAndTopics.pdf -- http://mail.python.org/mailman/listinfo/python-list
FM synthesis using Numpy
Hello fellow Python coders, I'm trying to build a simple FM synthesizer in Python. As a beginner, I take 'FM synthesizer' to mean: using a sine wave to control the frequency of another sine wave. I tried to generate a tone of 1000 Hz that deviates 15 Hz six times a second. The start of the resulting wave file sounds right, i.e., a vibrato effect can be heard. After a second or so, the vibrato becomes more and more extreme, as if the modulating oscillator's amplitude is rising over time. I suspect that I am misunderstanding the math. I tried a couple of things: - removing the factor 2 * num.pi from either of the oscillators does not fix it, besides, doing so is even more wrong because numpy.sin works with radians - using a higher sampling frequency makes no difference - making t run from 0 to 1 each second (t %= 1) causes a clipping of the sound, so this seems wrong too - the problem is not related to Numpy, because the effect also happens in pure-Python implementations of my bug As you can see, I'm at a loss and am even trying incorrect bugfixes. Any help would be very welcome. Thanks for your time, Joost Molenaar [I left out a writewavheader function to aid brevity] --- import numpy as num def oscillator(x, freq=1, amp=1, base=0, phase=0): return base + amp * num.sin(2 * num.pi * freq * x + phase) def writewav(filename, data): wave = open(filename, 'wb') # .wav header: 30 s at 44100 Hz, 1 channel of 16 bit signed samples wave.write('RIFF\x14`(\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00D' '\xac\x00\x00\x88X\x01\x00\x02\x00\x10\x00data\xf0_(\x00') # write float64 data as signed int16 (32767 * data).astype(num.int16).tofile(wave) wave.close() t = num.arange(0, 30, 1./44100) freq = oscillator(t, freq=6, amp=15, base=1000) tone = oscillator(t, freq=freq, amp=0.1) writewav('spam.wav', tone) --- -- http://mail.python.org/mailman/listinfo/python-list