os.putenv() has no effect

2013-06-18 Thread Johannes Bauer
Hi group, I've tracked down a bug in my application to a rather strange phaenomenon: os.putenv() doesn't seem to have any effect on my platform (x86-64 Gentoo Linux, Python 3.2.3): >>> os.getenv("PATH") '/usr/joebin:/usr/local/bin:/usr/bin:/bin:/usr/games/bin:/usr/sbin:/sbin:~/bin' >>> os.putenv(

Re: os.putenv() has no effect

2013-06-18 Thread Johannes Bauer
On 18.06.2013 19:24, inq1ltd wrote: > if you are trying to add a dir to a linux path you need > to understand how to add or change environment variables. Yeah, about this; I actually am fully aware of what I'm doing. > research this; > $ export PATH= $PATH: ???/???/??? You really couldn't h

Re: os.putenv() has no effect

2013-06-18 Thread Johannes Bauer
On 18.06.2013 20:09, Dave Angel wrote: > In other words, you shouldn't use putenv(), but instead modify os.environ. Huh... this is surprising to me. Because I actually looked it up in the manual and vaguely remember that there stood that os.environ is just a copy of the environment variables at i

Re: os.putenv() has no effect

2013-06-18 Thread Johannes Bauer
On 18.06.2013 20:12, Johannes Bauer wrote: > I am extremely certain that I found that passage, but can't find it > right now anymore (probably staring right at it and can't find it still) :-/ Obviously, yes: Note On some platforms, including FreeBSD and Mac OS X, setting e

Re: Why is regex so slow?

2013-06-18 Thread Johannes Bauer
On 18.06.2013 19:20, Chris Angelico wrote: > Yeah, I'd try that against 3.3 before opening a performance bug. Also, > it's entirely possible that performance is majorly different in 3.x > anyway, on account of strings being Unicode. Definitely merits another > look imho. Hmmm, at least Python 3.2

Re: Why is regex so slow?

2013-06-19 Thread Johannes Bauer
On 18.06.2013 22:30, Grant Edwards wrote: > All the O() tells you is the general shape of the line. Nitpick: it only gives an *upper bound* for the complexity. Any function that is within O(n) is also within O(n^2). Usually when people say O() they actually mean capital Thetha (which is the corre

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Johannes Bauer
On 25.07.2013 07:48, Steven D'Aprano wrote: > Then you aren't looking very closely. d.keys() returns a set-like view > into the dict, which is great for comparing elements: > > py> d1 = dict.fromkeys([1, 2, 3, 4]) > py> d2 = dict.fromkeys([3, 4, 5, 6]) > py> d1.keys() & d2.keys() # keys that ar

Re: Comparing strings from the back?

2012-09-04 Thread Johannes Bauer
On 04.09.2012 04:17, Steven D'Aprano wrote: > On average, string equality needs to check half the characters in the > string. How do you arrive at that conclusion? When comparing two random strings, I just derived n = (256 / 255) * (1 - 256 ^ (-c)) where n is the average number of character co

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 04.09.2012 20:07, Steven D'Aprano wrote: > A reasonable, conservative assumption is to calculate the largest > possible value of the average for random strings. That largest value > occurs when the alphabet is as small as possible, namely two characters. > In practice, strings come from a lar

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 04.09.2012 23:59, Chris Angelico wrote: >> n = (256 / 255) * (1 - 256 ^ (-c)) >> >> where n is the average number of character comparisons and c. The >> rationale as follows: The first character has to be compared in any >> case. The second with a probability of 1/256, the third with 1/(256^2)

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 11:24, Johannes Bauer wrote: > Consider sorting a large dictionary. Sorting is in O(n log(n)), but this > assumes O(1) comparisons! If the comparison operation itself were in > O(n), the total sorting complexity would be O(n^2 log(n)), which is > definitely false. Most

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 04:18, Neil Hodgson wrote: >The memcpy patch was controversial as it broke Adobe Flash which > assumed memcpy was safe like memmove. Adobe Flash was broken before, making an assumption that is not guaranteed by the standard. The patch only showed the problem. Regards, Johannes

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 16:30, Steven D'Aprano wrote: > Since these are *completely different Ns*, you can't combine them to get > O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer > nonsense. If you state it like this: Yes, you are correct here. > You are making unjustified assumpt

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 05.09.2012 18:24, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>>

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 10:33, Steven D'Aprano wrote: > But you know, it really doesn't make a difference. Equality testing will > *still* be O(N) since the asymptomatic behaviour for sufficiently large > string comparisons will be bounded by O(N). Multiplicative constants > ("half the string" versus "0.

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 16:23, Dave Angel wrote: > On 09/06/2012 09:43 AM, Johannes Bauer wrote: >> >> Yes, worst-case is O(N), best case O(1). Average is O(n log n). > > Can't see how you came up with an average of n log(n). Fourteen minutes > before you made this post, you

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 15:43, Johannes Bauer wrote: > Wrong, at least for randomized strings (i.e. every character with the > same probability). O(N) is worst-case, O(log N) is correct for > randomized strings. ^^ Here I write the right thing. Then further below... > Yes, worst-case is O(N),

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 16:23, Dave Angel wrote: > On 09/06/2012 09:43 AM, Johannes Bauer wrote: >> >> Yes, worst-case is O(N), best case O(1). Average is O(n log n). > > Can't see how you came up with an average of n log(n). Fourteen minutes > before you made this post, you

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 16:39, Chris Angelico wrote: > In any case, it'll be far FAR more useful than arguing from > totally random, or random word selection, or anything. > > Who's game? Okay, patched against Python 3.2.3: http://pastebin.com/PRRN53P6 To invoke display of the stats, compare the string "

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 17:36, Johannes Bauer wrote: > "pleasedumpstats" < "" And against a XML-reading C code generator that uses mako: strCmpEq 39670 strCmpLt 2766215 strCmpGt 2744002 strCmpTc 37430821 strCmpCc 14048656 Compared strings: 5549887 Equal: 0.7% Average word

Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Johannes Bauer
Hi there, I'm currently looking for a good solution to the following problem: I have two classes A and B, which interact with each other and which interact with the user. Instances of B are always created by A. Now I want A to call some private methods of B and vice versa (i.e. what C++ "friends"

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Johannes Bauer
On 29.10.2012 17:47, Chris Angelico wrote: > The usual convention for private methods is a leading underscore on the name: Yup, that's what I'm using. > It's only a convention, though; it doesn't make it "hard" to call > them, it just sends the message "this is private, I don't promise that > it

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Johannes Bauer
On 29.10.2012 17:52, Grant Edwards wrote: > By "decleare them privide" do you mean using __ASDF__ name-munging? > > It sounds to me like you're just making life hard on yourself. Gaah, you are right. I just noticed that using the single underscore (as I do) does not restrict usage in any "no

Relative imports in packages

2012-11-09 Thread Johannes Bauer
Hi list, I've these two minor problems which bothered me for quite some time, maybe you can help me. I'm using Python 3.2. For some project I have a component in its own package. Let's say the structure looks like this: pkg/__init__.py pkg/Foo.py pkg/Bar.py Foo.py and Bar.py contain their class

Re: Generate unique ID for URL

2012-11-14 Thread Johannes Bauer
On 14.11.2012 01:41, Richard Baron Penman wrote: > I found the MD5 and SHA hashes slow to calculate. Slow? For URLs? Are you kidding? How many URLs per second do you want to calculate? > The builtin hash is fast but I was concerned about collisions. What > rate of collisions could I expect? MD5

Re: Generate unique ID for URL

2012-11-14 Thread Johannes Bauer
On 14.11.2012 02:39, Roy Smith wrote: > The next step is to reduce the number of bits you are encoding. You > said in another post that "1 collision in 10 million hashes would be > tolerable". So you need: > math.log(10*1000*1000, 2) > 23.25349666421154 > > 24 bits worth of key. Nope

Re: Generate unique ID for URL

2012-11-14 Thread Johannes Bauer
On 14.11.2012 13:33, Dave Angel wrote: > Te birthday paradox could have been important had the OP stated his goal > differently. What he said was: > > """Ideally I would want to avoid collisions altogether. But if that means > significant extra CPU time then 1 collision in 10 million hashes wou

Greedy parsing of argparse/positional arguments

2012-11-20 Thread Johannes Bauer
Hi list, I have a problem with Python3.2's argparse module. The following sample: parser = argparse.ArgumentParser(prog = sys.argv[0]) parser.add_argument("-enc", metavar = "enc", nargs = "+", type = str, default = [ "utf-8" ]) parser.add_argument("pattern", metavar = "pattern", type = str, nargs

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Johannes Bauer
On 19.12.2012 15:23, wxjmfa...@gmail.com wrote: > I was using the German word "Straße" (Strasse) — German > translation from "street" — to illustrate the catastrophic and > completely wrong-by-design Unicode handling in Py3.3, this > time from a memory point of view (not speed): > sys.getsiz

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Johannes Bauer
On 19.12.2012 16:18, Johannes Bauer wrote: > How do those arbitrary numbers prove anything at all? Why do you draw > the conclusion that it's broken by design? What do you expect? You're > very vague here. Just to show how ridiculously pointless your numers > are, yo

Python3 + sqlite3: Where's the bug?

2012-12-20 Thread Johannes Bauer
Hi group, I've run into a problem using Python3.2 and sqlite3 db access that I can't quite wrap my head around. I'm pretty sure there's a bug in my program, but I can't see where. Help is greatly appreciated. I've created a minimal example to demonstrate the phaenomenon (attached at bottom). Firs

Re: Py 3.3, unicode / upper()

2012-12-20 Thread Johannes Bauer
On 19.12.2012 16:40, Chris Angelico wrote: > You may not be familiar with jmf. He's one of our resident trolls, and > he has a bee in his bonnet about PEP 393 strings, on the basis that > they take up more space in memory than a narrow build of Python 3.2 > would, for a string with lots of BMP cha

Re: Python3 + sqlite3: Where's the bug?

2012-12-20 Thread Johannes Bauer
On 20.12.2012 16:05, Chris Angelico wrote: > On Fri, Dec 21, 2012 at 1:52 AM, Johannes Bauer wrote: >> def fetchmanychks(cursor): >> cursor.execute("SELECT id FROM foo;") >> while True: >> result = cursor.fetchmany() &

Binding first parameter of method to constant value

2012-05-18 Thread Johannes Bauer
Hi group, I'm trying to dynamically add methods to a class at runtime. What I would like to do is have them all delegated to one common function which is called with the name of the function as first parameter. I.e.: class Foo(): def __init__(self): # Some magic missing here setattr(sel

Re: Binding first parameter of method to constant value

2012-05-18 Thread Johannes Bauer
On 18.05.2012 15:10, Steven D'Aprano wrote: > Here's one way: > > import types > class K(object): > def _dispatcher(self, name, *args): > print "called from", name, args > def __init__(self): > setattr(self, 'foometh', > types.MethodType( >

ctype C library call always returns 0 with Python3

2012-05-19 Thread Johannes Bauer
Hi group, I'm playing with ctypes and using it to do regressions on some C code that I compile as a shared library. Python is the testing framework. This works nicely as long as I do not need the return value (i.e. calling works as expected and parameters are passed correctly). The return value o

Brainstorming on recursive class definitions

2017-09-12 Thread Johannes Bauer
Hi group, so I'm having a problem that I'd like to solve *nicely*. I know plenty of ways to solve it, but am curious if there's a solution that allows me to write the solution in a way that is most comfortable for the user. I'm trying to map registers of a processor. So assume you have a n bit ad

Re: Brainstorming on recursive class definitions

2017-09-12 Thread Johannes Bauer
By the way, here's my work in progress: https://gist.github.com/johndoe31415/7e432b4f47f0030f0903dbd6a401e5dc I really really love the look & feel, but am unsure if there's a better way for this? Cheers, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich

Creating lambdas inside generator expression

2022-06-29 Thread Johannes Bauer
Hi list, I've just encounted something that I found extremely unintuitive and would like your feedback. This bit me *hard*, causing me to question my sanity for a moment. Consider this minimal example code (Py 3.10.4 on Linux x64): class Msg(): def hascode(self, value): p

Re: Creating lambdas inside generator expression

2022-06-29 Thread Johannes Bauer
Aha! conds = [ lambda msg, z = z: msg.hascode(z) for z in ("foo", "bar") ] Is what I was looking for to explicitly use the value of z. What a caveat, didn't see that coming. Learning something new every day. Cheers, Joe Am 29.06.22 um 11:50 schrieb Johannes Bauer:

Evaluation of variable as f-string

2023-01-23 Thread Johannes Bauer
Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? I.e., what I want is to be able to do this: x = { "y": "z" } print(f"-> {x['y']}") This prints "-> z", as expected. But consider: x = { "y": "z" } s = "-> {x['y']}" print(s.format(

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 23.01.23 um 19:02 schrieb Chris Angelico: This is supposedly for security reasons. However, when trying to emulate this behavior that I wanted (and know the security implications of), my solutions will tend to be less secure. Here is what I have been thinking about: If you really want the f

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 25.01.23 um 20:38 schrieb Thomas Passin: x = { "y": "z" } s = "-> {target}" print(s.format(target = x['y'])) Stack overflow to the rescue: No. Search phrase:  "python evaluate string as fstring" https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string de

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 23.01.23 um 17:43 schrieb Stefan Ram: Johannes Bauer writes: x = { "y": "z" } s = "-> {x['y']}" print(s.format(x = x)) x = { "y": "z" } def s( x ): return '-> ' + x[ 'y' ] print( s( x = x )) Exce

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 27.01.23 um 20:18 schrieb Chris Angelico: All you tell us is what you're attempting to do, which there is *no good way to achieve*. Fair enough, that is the answer. It's not possible. Perhaps someone will be inspired to write a function to do it. 😎 See, we don't know what "it" is, so it

Re: Evaluation of variable as f-string

2023-01-28 Thread Johannes Bauer
Am 28.01.23 um 02:51 schrieb Thomas Passin: This is literally the version I described myself, except using triple quotes. It only modifies the underlying problem, but doesn't solve it. Ok, so now we are in the territory of "Tell us what you are trying to accomplish". And part of that is why y

Re: Evaluation of variable as f-string

2023-01-28 Thread Johannes Bauer
Am 28.01.23 um 00:41 schrieb Chris Angelico: On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list wrote: Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. The exact same points have already been made, but not listened t

Re: Evaluation of variable as f-string

2023-01-28 Thread Johannes Bauer
Am 27.01.23 um 23:10 schrieb Christian Gollwitzer: Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not: x = { "y": "z"

Re: Evaluation of variable as f-string

2023-01-29 Thread Johannes Bauer
Am 29.01.23 um 02:09 schrieb Chris Angelico: The exact same points have already been made, but not listened to. Sometimes, forceful language is required in order to get people to listen. An arrogant bully's rationale. Personally, I'm fine with it. I've been to Usenet for a long time, in which

Re: Evaluation of variable as f-string

2023-01-29 Thread Johannes Bauer
Am 29.01.23 um 05:27 schrieb Thomas Passin: Well, yes, we do see that.  What we don't see is what you want to accomplish by doing it, and why you don't seem willing to accept some restrictions on the string fragments so that they will evaluate correctly. I'll have to accept the restrictions.

threading and multiprocessing deadlock

2021-12-05 Thread Johannes Bauer
Hi there, I'm a bit confused. In my scenario I a mixing threading with multiprocessing. Threading by itself would be nice, but for GIL reasons I need both, unfortunately. I've encountered a weird situation in which multiprocessing Process()es which are started in a new thread don't actually start

Re: threading and multiprocessing deadlock

2021-12-06 Thread Johannes Bauer
Am 06.12.21 um 13:56 schrieb Martin Di Paola: > Hi!, in short your code should work. > > I think that the join-joined problem is just an interpretation problem. > > In pseudo code the background_thread function does: > > def background_thread() >   # bla >   print("join?") >   # bla >   print("j

Re: Magic UTF-8/Windows-1252 encodings

2016-08-30 Thread Johannes Bauer
On 29.08.2016 17:59, Chris Angelico wrote: > Fair enough. If this were something that a lot of programs wanted, > then yeah, there'd be good value in stdlibbing it. Character encodings > ARE hard to get right, and this kind of thing does warrant some help. > But I think it's best not done in core

Lexer/Parser question: TPG

2016-11-14 Thread Johannes Bauer
Hi group, this is not really a Python question, but I use Python to lex/parse some input. In particular, I use the amazing TPG (http://cdsoft.fr/tpg/). However, I'm now stuck at a point and am sure I'm not doing something correctly -- since there's a bunch of really smart people here, I hope to ge

Re: Entering a very large number

2018-03-23 Thread Johannes Bauer
On 23.03.2018 14:01, ast wrote: > It is not beautiful and not very readable. It is better to > have a fixed number of digits per line (eg 50) Oh yes, because clearly a 400-digit number becomes VERY beautiful and readable once you add line breaks to it. Cheers, Joe -- >> Wo hattest Du das Beben

Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
Hey group, I stumbled about something that I cannot quite explain while doing some stupid naming of variables in my code, in particular using "collections" as an identifier. However, what results is strange. I've created a minimal example. Consider this: import collections class Test(object):

Re: Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
On 30.03.2018 13:13, Ben Bacarisse wrote: >> import collections >> >> class Test(object): >> def __init__(self): >> z = { >> "y": collections.defaultdict(list), > > This mention of collections refers to ... > >> } >> for (_, collec

Re: Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
On 30.03.2018 13:25, Johannes Bauer wrote: >> This mention of collections refers to ... >> >>> } >>> for (_, collections) in z.items(): >> >> ... this local variable. > > Yup, but why? I mean, at the point of definition of

Re: Curious case of UnboundLocalError

2018-03-31 Thread Johannes Bauer
On 30.03.2018 16:46, Ben Bacarisse wrote: >> Yup, but why? I mean, at the point of definition of "z", the only >> definition of "collections" that would be visible to the code would be >> the globally imported module, would it not? How can the code know of the >> local declaration that only comes

pytz and Python timezones

2016-06-11 Thread Johannes Bauer
Hi there, first off, let me admit that I have a hard time comprehensively wrapping my head around timezones. Everything around them is much more complicated than it seems, IMO. That said, I'm trying to do things the "right" way and stumbled upon some weird issue which I can't explain. I'm unsure w

Re: value of pi and 22/7

2016-06-18 Thread Johannes Bauer
On 18.06.2016 01:12, Lawrence D’Oliveiro wrote: > I’m not sure how you can write “30” with one digit... 3e1 has one significant digit. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere

Zero runtime impact tracing

2016-07-30 Thread Johannes Bauer
Hi group, I'm using CPython 3.5.1. Currently I'm writing some delicate code that is doing the right thing in 99% of the cases and screws up on the other 1%. I would like to have tracing in some very inner loops: if self._debug: print("Offset %d foo bar" % (self._offset)) However, this incurs

Pythonic custom multi-line parsers

2019-07-10 Thread Johannes Bauer
Hi list, I'm looking for ideas as to a pretty, Pythonic solution for a specific problem that I am solving over and over but where I'm never happy about the solution in the end. It always works, but never is pretty. So see this as an open-ended brainstorming question. Here's the task: There's a cu

Re: GPG wrapper, ECC 25519 compatible?

2019-09-02 Thread Johannes Bauer
On 03.09.19 05:28, rmli...@riseup.net wrote: > But I just don't understand how to get > and pass information back to the gpg command line prompts at all, not to > mention automating the process. The manpage describes how to enable the machine-parsable interface, which is exactly what you want. Th

Handling of disconnecting clients in asyncio

2019-09-24 Thread Johannes Bauer
Hi group, I'm trying to get into async programming using Python. Concretely I open a UNIX socket server in my application. The UNIX socket server generates events and also receives commands/responds to them. I do this by: async def _create_local_server(self): await asyncio.start_unix_server(

'%Y' in strftime() vs. strptime()

2019-12-29 Thread Johannes Bauer
Hi list, I've just stumbled upon a strange phaenomenon and I'm wondering if it's a bug. Short and sweet: Python 3.7.3 (default, Oct 7 2019, 12:56:13) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from datetime import datetime as d >>> x = d(1,

Programming puzzle with boolean circuits

2013-12-09 Thread Johannes Bauer
Hi group, it's somewhat OT here, but I have a puzzle to which I would like a solution -- but I'm unsure how I should tackle the problem with Python. But it's a fun puzzle, so maybe it'll be appreciated here. The question is: How do you design a boolean circuit that contains at most 2 NOT gates, b

Re: Programming puzzle with boolean circuits

2013-12-11 Thread Johannes Bauer
On 09.12.2013 14:25, Chris Angelico wrote: >> I found this puzzle again and was thinking about: How would I code a >> brute-force approach to this problem in Python? > > Ooooh interesting! Ha, I thought so too :-) > Well, here's a start: There's no value in combining the same value in > an AND

Re: Blog "about python 3"

2014-01-05 Thread Johannes Bauer
On 31.12.2013 10:53, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> http://blog.startifact.com/posts/alex-gaynor-on-python-3.html. > > I quote: > > "...perhaps a brave group of volunteers will stand up and fork Python 2, and > take the incremental steps forward. This will have to remain just

Possible bug with stability of mimetypes.guess_* function output

2014-02-07 Thread Johannes Bauer
Hi group, I'm using Python 3.3.2+ (default, Oct 9 2013, 14:50:09) [GCC 4.8.1] on linux and have found what is very peculiar behavior at best and a bug at worst. It regards the mimetypes module and in particular the guess_all_extensions and guess_extension functions. I've found that these do not

Re: Possible bug with stability of mimetypes.guess_* function output

2014-02-07 Thread Johannes Bauer
On 07.02.2014 20:09, Asaf Las wrote: > it might be you could try to query using sequence below : > > import mimetypes > mimetypes.init() > mimetypes.guess_extension("text/html") > > i got only 'htm' for 5 consequitive attempts Doesn't change anything. With this: #!/usr/bin/python3 import mime

Re: raise None

2015-12-31 Thread Johannes Bauer
On 31.12.2015 01:09, Steven D'Aprano wrote: > Obviously this doesn't work now, since raise None is an error, but if it did > work, what do you think? I really like the idea. I've approached a similar problem with a similar solution (also experimented with decorators), but the tracebacks really ar

Re: raise None

2016-01-02 Thread Johannes Bauer
On 31.12.2015 21:18, Ben Finney wrote: > As best I can tell, Steven is advocating a way to obscure information > from the traceback, on the assumption the writer of a library knows that > I don't want to see it. How do you arrive at that conclusion? The line that raises the exception is exactly t

Re: What is heating the memory here? hashlib?

2016-02-15 Thread Johannes Bauer
On 15.02.2016 03:21, Paulo da Silva wrote: > So far I tried the program twice and it ran perfectly. I think you measured your RAM consumption wrong. Linux uses all free RAM as HDD cache. That's what is used in "buffers". That is, it's not "free", but it would be free if any process would sbrk().

Idiomatic backtracking in Python

2015-01-25 Thread Johannes Bauer
Hi folks, I have a problem at hand that needs code for backtracking as a solution. And I have no problem coding it, but I can't get rid of the feeling that I'm always solving backtracking problems in a non-Pythonic (non-idiomatic) way. So, I would like to ask if you have a Pythonic approach to bac

Re: sqlite3 and dates

2015-02-18 Thread Johannes Bauer
On 18.02.2015 08:05, Chris Angelico wrote: > But if you need more facilities than SQLite3 can offer, maybe it's > time to move up to a full database server, instead of local files. > Switching to PostgreSQL will give you all those kinds of features, > plus a lot of other things that I would have t

Re: sqlite3 and dates

2015-02-18 Thread Johannes Bauer
On 18.02.2015 12:21, Chris Angelico wrote: > SQLite3 is fine for something that's basically just a more structured > version of a flat file. You assume that nobody but you has the file > open, and you manipulate it just the same as if it were a big fat blob > of JSON, but thanks to SQLite, you don

Re: sqlite3 and dates

2015-02-18 Thread Johannes Bauer
On 18.02.2015 13:14, Chris Angelico wrote: > On Wed, Feb 18, 2015 at 10:57 PM, Johannes Bauer wrote: >> SQLite and Postgres are so vastly different in their setup, >> configuration, capabilities and requirements that the original developer >> has to have done a MAJOR error i

Re: YADTR (Yet Another DateTime Rant)

2014-03-27 Thread Johannes Bauer
On 26.03.2014 10:53, Jean-Michel Pichavant wrote: > Note : I don't see what's wrong in your example, however I have the feeling > the term "stupiditie" is a little bit strong ;) The problem is that for a given timedelta t with t > 0 it is intuitive to think that its string representation str(t)

Re: YADTR (Yet Another DateTime Rant)

2014-03-27 Thread Johannes Bauer
On 27.03.2014 01:16, Steven D'Aprano wrote: > py> divmod(30, 24) > (1, 6) > > That makes perfect intuitive sense: 30 hours is 1 day with 6 hours > remaining. In human-speak, we'll say that regardless of whether the > timedelta is positive or negative: we'll say "1 day and 6 hours from now" > o

Re: YADTR (Yet Another DateTime Rant)

2014-03-27 Thread Johannes Bauer
On 27.03.2014 11:44, Chris Angelico wrote: > On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer wrote: >> Besides, there's an infinite amount of (braindead) timedelta string >> representations. For your -30 hours, it is perfectly legal to say >> >> 123 days, -2982 hou

Re: YADTR (Yet Another DateTime Rant)

2014-03-27 Thread Johannes Bauer
On 27.03.2014 11:44, Chris Angelico wrote: > It's not "equally braindead", it follows a simple and logical rule: > Only the day portion is negative. The more I think about it, the sillier this rule seems to me. A timedelta is a *whole* object. Either the whole delta is negative or it is not. It

Re: checking if two things do not equal None

2014-03-29 Thread Johannes Bauer
On 29.03.2014 20:05, Steven D'Aprano wrote: > On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: > >> if (a, b) != (None, None): >> or >> if a != None != b: >> >> Preference? Pros? Cons? Alternatives? > > if not (a is b is None): ... > > Or if you prefer: > > if a is not b is not None: ..

Re: checking if two things do not equal None

2014-03-29 Thread Johannes Bauer
On 29.03.2014 22:07, Roy Smith wrote: > I agree with that. But > >> if (a, b) != (None, None): > > seems pretty straight-forward to me too. In fact, if anything, it seems > easier to understand than > >> if (a is not None) or (b is not None): Yes, probably. I liked the original, too. If I w

Re: checking if two things do not equal None

2014-03-29 Thread Johannes Bauer
On 29.03.2014 22:55, Johannes Bauer wrote: >>> if (a is not None) or (b is not None): > > Yes, probably. I liked the original, too. If I were writing the code, > I'd probably try to aim to invert the condition though and simply do > > if (a is None) and (b is None)

Re: Everything you did not want to know about Unicode in Python 3

2014-05-13 Thread Johannes Bauer
On 13.05.2014 03:18, Steven D'Aprano wrote: > Armin Ronacher is an extremely experienced and knowledgeable Python > developer, and a Python core developer. He might be wrong, but he's not > *obviously* wrong. He's correct about file name encodings. Which can be fixed really easily wihtout messi

Re: Everything you did not want to know about Unicode in Python 3

2014-05-13 Thread Johannes Bauer
On 13.05.2014 10:38, Chris Angelico wrote: >> Python 2's ambiguity allows me not to answer the tough philosophical >> questions. I'm not saying it's necessarily a good thing, but it has its >> benefits. > > It's not a good thing. It means that you have the convenience of > pretending there's no p

Re: Everything you did not want to know about Unicode in Python 3

2014-05-13 Thread Johannes Bauer
On 13.05.2014 10:25, Marko Rauhamaa wrote: > Based on my background (network and system programming), I'm a bit > suspicious of strings, that is, text. For example, is the stuff that > goes to syslog bytes or text? Does an XML file contain bytes or > (encoded) text? The answers are not obvious to

Re: PEP 8 : Maximum line Length :

2014-05-15 Thread Johannes Bauer
On 15.05.2014 04:43, Ben Finney wrote: > Rustom Mody writes: > >> Until then may we relegate '79' to quaint historical curiosities > > Not until the general capacity of human cognition advances to make > longer lines easier to read. I find it surprising how you can make such a claim about the w

Re: Python is horribly slow compared to bash!!

2014-05-26 Thread Johannes Bauer
On 22.05.2014 15:43, wxjmfa...@gmail.com wrote: > I can take the same application and replace 'z' by ..., and > ... No, I do not win :-( . Python fails. That's nothing. I can make an application a TOUSAND times slower by changing the constant 1 to a 2. Python is such utter garbage! import time

Re: Python 3 is killing Python

2014-05-28 Thread Johannes Bauer
On 28.05.2014 21:23, Larry Martell wrote: > Somthing I came across in my travels through the ether: > > https://medium.com/@deliciousrobots/5d2ad703365d/ Sub-headline "The Python community should fork Python 2". Which could also read "Someone else should REALLY fork Py2 because I'm mad about Py3

Re: Python 3 is killing Python

2014-05-31 Thread Johannes Bauer
On 31.05.2014 12:07, Steve Hayes wrote: > So I bought this book, and decided that whatever version of Python it deals > with, that's the one I will download and use. This sounds like remarkably bad advice. That's like saying "I bought a can of motor oil in my department store and whatever engine

Re: Python 3 is killing Python

2014-06-02 Thread Johannes Bauer
On 02.06.2014 18:21, Roy Smith wrote: > Are we talking Tolkien trolls, Pratchett trolls, Rowling trolls, D&D > trolls, WoW trolls, or what? Details matter. Monkey Island trolls, obviously. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich

Re: Basic Python Query

2013-08-21 Thread Johannes Bauer
On 21.08.2013 11:11, Ulrich Eckhardt wrote: > That said, there is never a need for deriving > from the Thread class, you can also use it to run a function without > that. That way is IMHO clearer because the threading.Thread instance is > not the thread, just like a File instance is not a file. Bo

Re: Basic Python Query

2013-08-22 Thread Johannes Bauer
On 22.08.2013 00:50, Fábio Santos wrote: >>> That said, there is never a need for deriving >>> from the Thread class, you can also use it to run a function without >>> that. That way is IMHO clearer because the threading.Thread instance is >>> not the thread, just like a File instance is not a fil

Re: Basic Python Query

2013-08-22 Thread Johannes Bauer
On 22.08.2013 02:06, Ned Batchelder wrote: >> I cannot tell whether you are trolling or are just new to this, but >> you don't always have to use threads. You use threads when you need >> multiple parts of your program running concurrently. Don't inherit >> Thread if all you are doing is a simple

Re: pycrypto: what am I doing wrong?

2013-10-24 Thread Johannes Bauer
On 24.10.2013 09:07, Chris Angelico wrote: > On Thu, Oct 24, 2013 at 4:22 PM, Paul Pittlerson > wrote: >> msg = cipher.encrypt(txt) >> > '|s\x08\xf2\x12\xde\x8cD\xe7u*' >> >> msg = cipher.encrypt(txt) >> > '\xa1\xed7\xb8h> >> # etc > AES is a stream cipher; No, it is definitely not! It'

Re: pycrypto: what am I doing wrong?

2013-10-24 Thread Johannes Bauer
On 24.10.2013 07:22, Paul Pittlerson wrote: > What am I doing wrong? You're not reinitializing the internal state of the crypto engine. When you recreate "cipher" with the same IV every time, it will work. Best regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindes

Re: pycrypto: what am I doing wrong?

2013-10-24 Thread Johannes Bauer
On 24.10.2013 09:33, Johannes Bauer wrote: > On 24.10.2013 07:22, Paul Pittlerson wrote: > >> What am I doing wrong? > > You're not reinitializing the internal state of the crypto engine. When > you recreate "cipher" with the same IV every time, it will

Python3 doc, operator reflection

2013-10-28 Thread Johannes Bauer
Hi group, in http://docs.python.org/3/reference/datamodel.html#customization the doc reads: > There are no swapped-argument versions of these methods (to be used when the > left argument does not support the operation but the right argument does); > rather, __lt__() and __gt__() are each other’

  1   2   3   >