Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Alexander Blinne
On 19.06.2012 18:23, Edward C. Jones wrote: > Consider the following line in C: >printf('%a\n', x); > where x is a float or double. This outputs a hexadecimal representation > of x. Can I do this in Python? Don't know why there is no format character %a or %A in python, but the conversion is

Re: 2 + 2 = 5

2012-07-05 Thread Alexander Blinne
On 05.07.2012 16:34, Laszlo Nagy wrote: five.contents[five.contents[:].index(5)] = 4 5 > 4 5 is 4 > True That's surprising, because even after changing 5 to 4 both objects still have different id()s (tested on Py2.7), so 5 is 4 /should/ still be False (But isn't on my 2.7). But that

Re: [CGI] Why is HTML not rendered?

2012-08-17 Thread Alexander Blinne
On 17.08.2012 15:27, Gilles wrote: > For some reason, this CGI script that I found on Google displays the > contents of the variable but the HTML surrounding it is displayed > as-is by the browser instead of being rendered: > print "Content-Type: text/plain;charset=utf-8" With this line you tell

Re: Objects in Python

2012-08-24 Thread Alexander Blinne
On 23.08.2012 20:30, Dennis Lee Bieber wrote: > On Thu, 23 Aug 2012 15:33:33 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: >> x = 1; >> >> In C, this means: Assign the integer 1 to the variable x (possibly >> with implicit type casting, eg to floating point). >> >

Re: issue with struct.unpack

2012-08-26 Thread Alexander Blinne
On 26.08.2012 01:31, Dennis Lee Bieber wrote: > The struct module relies upon the user knowing the format of the data. > If your problem is that you have some null-terminated string data in a > variable width field, you will have to locate the position of the null > FIRST, and specify the appropria

Re: Python presentations

2012-09-13 Thread Alexander Blinne
On 13.09.2012 21:01, 8 Dihedral wrote: > def powerlist(x, n): > # n is a natural number > result=[] > y=1 > for i in xrange(n): > result.append(y) > y*=x > return result # any object in the local function can be returned def powerlist(x, n): result=

Re: Python presentations

2012-09-14 Thread Alexander Blinne
On 14.09.2012 00:38, Chris Angelico wrote: > On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: >> def powerlist(x,n): >> if n==1: >> return [1] >> p = powerlist(x,n-1) >> return p + [p[-1]*x] > > Eh, much simpler. > >

Re: Python presentations

2012-09-16 Thread Alexander Blinne
On 14.09.2012 14:19, Chris Angelico wrote: > Err, yes, I did mean ** there. The extra multiplications may be > slower, but which is worse? Lots of list additions, or lots of integer > powers? In the absence of clear and compelling evidence, I'd be > inclined to go with the list comp - and what's mo

Re: Python presentations

2012-09-17 Thread Alexander Blinne
On 16.09.2012 19:35, Steven D'Aprano wrote: > On Sun, 16 Sep 2012 18:13:36 +0200, Alexander Blinne wrote: >> def powerlist2(x,n): >> if n==1: >> return [1] >> p = powerlist3(x,n-1) >> p.append(p[-1]*x) >> return p > > Is

Re: Functional way to compare things inside a list

2012-09-21 Thread Alexander Blinne
On 21.09.2012 00:58, thorso...@lavabit.com wrote: > Hi, > > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] > > I want to check for a value (e.g. '4'), and get the key of the dictionary > that contains that value. > (Yep, this is bizarre.) > > some_magic(list, '4') > => '3' > > What's the func

Re: write binary with struct.pack_into

2012-10-06 Thread Alexander Blinne
First, you should consider reading the documentation of struct.unpack_from and struct.pack_into at http://docs.python.org/library/struct.html quite carefully. It says, that these commands take a parameter called offset, which names the location of the data in a buffer (e.g. an opened file). exampl

Re: creating size-limited tar files

2012-11-07 Thread Alexander Blinne
I don't know the best way to find the current size, I only have a general remark. This solution is not so good if you have to impose a hard limit on the resulting file size. You could end up having a tar file of size "limit + size of biggest file - 1 + overhead" in the worst case if the tar is at l

Re: Python Noob Question.

2012-12-03 Thread Alexander Blinne
Hello, by having a quick look at their website i found a plugin for CoreTemp which acts as a server and can be asked for status information of the cpu. Now your task is really simple: write a little function or class that opens a network socket, connects to that plugin und asks it for the informat

Re: Conversion of List of Tuples

2012-12-04 Thread Alexander Blinne
Am 03.12.2012 20:58, schrieb subhabangal...@gmail.com: > Dear Group, > > I have a tuple of list as, > > tup_list=[(1,2), (3,4)] > Now if I want to covert as a simple list, > > list=[1,2,3,4] > > how may I do that? Another approach that has not yet been mentioned here: >>> a=[(1,2), (3,4)] >>>

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Alexander Blinne
Another neat solution with a little help from http://stackoverflow.com/questions/1701211/python-return-the-index-of-the-first-element-of-a-list-which-makes-a-passed-fun >>> def split_product(p): ... w = p.split(" ") ... j = (i for i,v in enumerate(w) if v.upper() != v).next() ... retu

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Alexander Blinne
Am 04.12.2012 19:28, schrieb DJC: (i for i,v in enumerate(w) if v.upper() != v).next() > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'generator' object has no attribute 'next' Yeah, i saw this problem right after i sent the posting. It now is supposed to read

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Alexander Blinne
Am 04.12.2012 20:37, schrieb Ian Kelly: > >>> def split_product(p): > ... w = p.split(" ") > ... j = next(i for i,v in enumerate(w) if v.upper() != v) > ... return " ".join(w[:j]), " ".join(w[j:]) > > > It still fails if the product description is empty. That's true..

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Alexander Blinne
Am 05.12.2012 18:04, schrieb Nick Mellor: > Sample data Well let's see what def split_product(p): p = p.strip() w = p.split(" ") try: j = next(i for i,v in enumerate(w) if v.upper() != v) except StopIteration: return p, '' return " ".join(w[:j]), " ".join(w[j:]

Re: Python Noob Question.

2012-12-10 Thread Alexander Blinne
Am 05.12.2012 21:24, schrieb Owatch: > Thanks a TON for your answer thought, this is exactly what I really hoped for. > The problem for me is that I don't actually know anything about writing a > function that opens a network socket, and "connects to that plugin und asks > it for the > informati

Re: Preventing tread collisions

2012-12-13 Thread Alexander Blinne
Am 12.12.2012 21:29, schrieb Dave Angel: > On 12/12/2012 03:11 PM, Wanderer wrote: >> I have a program that has a main GUI and a camera. In the main GUI, you can >> manipulate the images taken by the camera. You can also use the menu to >> check the camera's settings. Images are taken by the came

Re: [newbie] problem making equally spaced value array with linspace

2012-12-18 Thread Alexander Blinne
Am 18.12.2012 13:37, schrieb Jean Dubois: > I have trouble with the code beneath to make an array with equally > spaced values > When I enter 100e-6 as start value, 700e-6 as end value and 100e-6 I > get the following result: > [ 0.0001 0.00022 0.00034 0.00046 0.00058 0.0007 ] > But I was hop

Re: Pattern-match & Replace - help required

2012-12-19 Thread Alexander Blinne
Am 19.12.2012 14:41, schrieb AT: > Thanks a million > Can you recommend a good online book/tutorial on regular expr. in python? http://docs.python.org/3/howto/regex.html -- http://mail.python.org/mailman/listinfo/python-list

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-22 Thread Alexander Blinne
Am 22.12.2012 13:45, schrieb prilisa...@googlemail.com: > Ps.: The Socket, the DB has to be kept allways open, because of it's Server > functionality, A lot of Sensors, Timers, User interaction, must recived , > Calculated, etc so a reaction must be send in about 16~100 ms, different > modules o

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-22 Thread Alexander Blinne
Am 22.12.2012 19:10, schrieb prilisa...@googlemail.com: > It's for me a view of top side down, but how could the midlevel comunicate to > each oter... "not hirachical" You could use something like the singleton pattern in order to get a reference to the same datastore-object every time Datastore.

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-22 Thread Alexander Blinne
Am 22.12.2012 21:43, schrieb prilisa...@googlemail.com: > I Think I describe my Situation wrong, the written Project is a > Server, that should store sensor data, perfoms makros on lamps according > a sequence stored in the DB and Rule systems schould regulate home devices > and plan scheduler job

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-24 Thread Alexander Blinne
bus) scheduler.do_things() if __name__=="__main__": main() Please feel free to ask specific questions about this approach. merry christmas everyone Alexander Blinne -- http://mail.python.org/mailman/listinfo/python-list

Re: Python recursive tree, linked list thingy

2012-03-07 Thread Alexander Blinne
Am 07.03.2012 20:49, schrieb Wanderer: I have a list of defective CCD pixels and I need to find clusters where a cluster is a group of adjacent defective pixels. This seems to me to be a classic linked list tree search.I take a pixel from the defective list and check if an adjacent pixel is in th

Documentation, assignment in expression.

2012-03-23 Thread Alexander Blinne
Hi, I think this section of the docs needs some kind of rewrite: While it is great to discuss the reasons for not allowing an assignment in an expression, I feel that the given example is some kind of outdate

Re: Documentation, assignment in expression.

2012-03-25 Thread Alexander Blinne
I am not sure I understand your argument. The doc section states that " [...] in Python you’re forced to write this: while True: line = f.readline() if not line: break ... # do something with line". That simply isn't true as one can simply write: for line in f: #do s

Re: Zipping a dictionary whose values are lists

2012-04-13 Thread Alexander Blinne
Am 12.04.2012 18:38, schrieb Kiuhnm: > Almost. Since d.values() = [[1,2], [1,2,3], [1,2,3,4]], you need to use > list(zip(*d.values())) > which is equivalent to > list(zip([1,2], [1,2,3], [1,2,3,4])) > > Kiuhnm While this accidently works in this case, let me remind you that d.values() do

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Alexander Blinne
Am 21.04.2012 05:25, schrieb Rotwang: > On 21/04/2012 01:01, Roy Smith wrote: >> In article<877gxajit0@dpt-info.u-strasbg.fr>, >> Alain Ketterlin wrote: >> >>> Tuples are immutable, while lists are not. >> >> If you really want to have fun, consider this classic paradox: >> > [] is [] >>

Re: why () is () and [] is [] work in other way?

2012-04-23 Thread Alexander Blinne
Am 21.04.2012 14:51, schrieb gst: > Hi, > > I played (python3.2) a bit on that and : > > case 1) Ok to me (right hand side is a tuple, whose elements are evaluated > one per one and have same effect as your explanation (first [] is destroyed > right before the second one is created) : > x

Re: which one do you prefer? python with C# or java?

2012-06-11 Thread Alexander Blinne
On 10.06.2012 23:27, Paul Rubin wrote: > Here is an exercise from the book that you might like to try in Python: > > http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_idx_3894 > > It's not easy ;-) I liked this exercize. At first I wrote my own merger. > def merge(*iterables): >

Re: which one do you prefer? python with C# or java?

2012-06-15 Thread Alexander Blinne
On 15.06.2012 09:00, Paul Rubin wrote: > Alexander Blinne writes: >>> def gen_s(): >>> s = [1] >>> m = skipdups(heapq.merge(*[(lambda j: (k*j for k in s))(n) for n in >>> [2,3,5]])) >>> yield s[0] >>> while True: >>>

Re: set environmental variable from python

2014-11-01 Thread Alexander Blinne
Am 31.10.2014 um 02:22 schrieb Artur Bercik: > I have to set environmental variable in my windows PC as follows: > > variable name: GISBASE > > value: C:\GRASS-64 > > Is it possible to set it from python? > > import sys > > sys.path.append("C:\\GRASS-64") > > But how to give variable name? I

Re: Reference

2014-03-04 Thread Alexander Blinne
Am 03.03.2014 19:48, schrieb Terry Reedy: > The 'is' operator has three uses, two intended and one not. In > production code, 'is' tests that an object *is* a particular singular > object, such as None or a sentinel instance of class object. Just a bit of statistics on this one from a recent small

Re: Reference

2014-03-04 Thread Alexander Blinne
Am 04.03.2014 15:06, schrieb Chris Angelico: > https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py I have always found it quite nice that the python parser is so easy to use from within python itself. > Run across the Python stdlib, that tells me there are 4040 uses of > is/is no

Re: Converting 5.223701009526849e-05 to 5e-05

2015-05-07 Thread Alexander Blinne
Am 03.05.2015 um 10:48 schrieb Ben Finney: > That's not as clear as it could be. Better is to be explicit about > choosing “exponential” format:: > > >>> foo = 5.223701009526849e-05 > >>> "{foo:5.0e}".format(foo=foo) > '5e-05' > Or even better the "general" format, which also works f

Re: Issue in printing top 20 dictionary items by dictionary value

2014-10-04 Thread Alexander Blinne
Am 04.10.2014 um 11:11 schrieb Shiva: > Hi All, > > I have written a function that > -reads a file > -splits the words and stores it in a dictionary as word(key) and the total > count of word in file (value). > > I want to print the words with top 20 occurrences in the file in reverse > order -

Re: Python 3.3 vs. MSDOS Basic

2013-02-18 Thread Alexander Blinne
Am 18.02.2013 20:13, schrieb John Immarino: > I coded a Python solution for Problem #14 on the Project Euler website. I was > very surprised to find that it took 107 sec. to run even though it's a pretty > simple program. I also coded an equivalent solution for the problem in the > old MSDOS ba

Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Alexander Blinne
Am 19.02.2013 12:42, schrieb Piet van Oostrum: > Terry Reedy writes: >> I find this surprising too. I am also surprised that it even works, >> given that the highest intermediate value is about 57 billion and I do >> not remember that Basic had infinite precision ints. > > That may explain why th

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Alexander Blinne
Am 07.03.2013 10:27, schrieb Sven: > Now I would like to iterate over P and place one N at each point. > However if you run out of N I'd like to restart from N[0] and carry on > until all the points have been populated. > So far I've got (pseudo code) > > i = 0 > for point in points: > put N[i

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Alexander Blinne
Am 08.03.2013 00:49, schrieb Alexander Blinne: > http://docs.python.org/3/library/itertools.html#itertools.repeat obviously I was aiming for http://docs.python.org/2/library/itertools.html#itertools.cycle here Greetings -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I iterate over a dictionary outside a function ?

2013-04-11 Thread Alexander Blinne
Am 11.04.2013 11:48, schrieb inshu chauhan: > I have a prog in which a functions returns a dict but when I try to > iterate over the dict using iterkeys, It shows an error. 1) Show us your code in form of a minimal "working" example, "working" means that it should show us what you expect it to do