Re: Tarfile and usernames

2012-12-31 Thread lars
On Sun, Dec 30, 2012 at 03:07:05PM -0500, Albert Hopkins wrote:
> > I can't see documented anywhere what this library does with userids and
> > groupids.  I can't guarantee that the computers involved will have the
> > same users and groups, and would like the archives to be extracted so
> > that the files are all owned by the extracting user.

> However, it should be stated that by default (on *nix anyway) if the
> user is not root then user/groups are assigned to the user exctracting
> the file (because only root can assign userids/non-member-groups).
> The TarFile extract*() methods pretty much inherit the same behavior as
> the *nix tar command.  So if you are extracting as a non-root user, you
> should expect the same behavoir.  If you are extracting as root but
> don't want to change user/groups may have to extract it manually or
> create your own class by inheriting TarFile and overriding the .chown()
> method.

Please take a look at the second example in the Examples section of the tarfile
docs:

http://docs.python.org/2.7/library/tarfile.html#examples

It shows how to extract a subset of an archive using a generator as some kind
of filter for the extractall() method. Just rewrite the example so that every
tarinfo is patched with the required user and group name information before
being yielded:

def filter(members):
for tarinfo in members:
tarinfo.uname = "root"
tarinfo.gname = "root"
yield tarinfo

That's it.

-- 
Lars Gustäbel
l...@gustaebel.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding user's home dir

2005-02-03 Thread Lars
Works great with Python 2.3.4 on...
dare I say it...
windows xp

>>> getHomeDir()
'C:\\Documents and Settings\\Lars'

Regards
Lars


Nemesis wrote:
> (..)
> Please, could you test it on your systems and tell me what you got?
> (..)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto, cls, wait commands

2005-02-13 Thread Lars
You sir are a troll for sure. QBasic?! When was the last time you did
any programming, 1989?  Gave me a laugh though.

Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternative to raw_input ?

2005-02-13 Thread Lars
Then may I suggest the keeping-it-simple approach:

def myGetch():
raw_input("Press Enter to continue")


(sorry about the dots, I'm using google groups)

Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stable GUI

2005-02-16 Thread Lars
Hi Viktor,

By fast what do you mean exactly? Imho all the usual gui-toolkits
pythonistas use are quite fast enough for most applications. You can
use Tkinter ofcourse, and with the extra "Tix" module you get lots
widgets. It's not the prettiest toolkit in the world, but it does the
job well.  And it's very programmer friendly.
A step up would be to use wxWindows or Qt (wxPython and pyQt
respectively), both are fast and stable as far as I know, and they are
more powerful than Tk, generally speaking.

Maybe you should describe your particular application and the reasons
why you really need lightspeed widget rendering ? Stability goes
without saying:)

Regards
Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stable GUI

2005-02-17 Thread Lars
I've used Tkinter quite extensively for various tools, but never for
anything big. I believe it will work nicely for a data input type of
application. I don't  know if you'll experience significant "lag" when
updating app-windows on old pentiums, but it shouldn't be a problem.
Mind you, the machines should have a decent amount of ram (I guess
around 128 mb and upwards is reasonable).
The only problem I've ever encountered was with updating Tk widgets
from threads in a threaded app - it won't work. The solution was
nothing worse than using an output queue, and having an event check the
output buffer every second or so.

The Tcl/TK crowd probably have more extensive experience with using Tk
and Tix for bigger long running apps, maybe you can ask them for more
info?

Good luck with your app!
Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shift Confusion

2005-02-25 Thread Lars
Hi Kamilche,

Aside from the 7bit confusion you should take a look at the 'struct'
module. I bet it will simplify your life considerably.

#two chars
>>> import struct
>>> struct.pack('cc','A','B')
'AB'

#unsigned short + two chars
>>> struct.pack('Hcc',65535,'a','b')
'\xff\xffab'


Cheers
Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ZoDB's capabilities

2005-03-01 Thread Lars
Quote Larry Bates:
> There is a VERY large website that uses Zope/ZODB that takes up to
> 9000 hits per second when it gets busy.

What's the url? I just got curious to see it a big site on Zope in
action.


-
Lars 
"Pythonfan stuck with c sharp"

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Appeal for python developers

2005-03-07 Thread Lars
Boogieman wrote:
> Please include "goto" command in future python realeses
> I know that proffesional programers doesn't like to use it,
> but for me as newbie it's too hard to get used replacing it
> with "while", "def" or other commands

I'm assuming you mean "python releases", "professional programmer"
and "command" == "keyword"/"statement"

I'm sorry for slapping the T-word on you in your last thread.
Considering
your background I don't think you necessarily want Python. Maybe this
is what your looking for:

freeBasic :  http://sourceforge.net/projects/fbc/
libertyBasic: http://lbpp.sourceforge.net/

I tested the first one and it took me back 15 years in a flash.

Cheers,
Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clearing the screen

2004-12-24 Thread Lars
Hi Iswor,

If I understand you correctly then your program is writing output to a
console/terminal window and you want to clear that window.
I don't know of any library methods for that, but you might just do:

os.system("cls")  #for windows
or
os.system("clear")   #for unix
Not the most advanced solution though.
---
Happy holidays! 
~Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Track keyboard and mouse usage

2006-07-18 Thread Lars
Diez B. Roggisch wrote:
> will make the devices world readable. While I haven't thought about any 
> security implications that might have (and am not especially 
> knowledgeable in such things to be honest), I'm convinced it is way less 
> likely to introduce any exploitable holes than suid root would.

Depending on what kind of info these devices produce, couldn't they be 
used to spy on someone typing in a password? (I can't check, I'm on 
FreeBSD.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write eof without closing

2006-08-19 Thread Lars
cage wrote:
> I want to use a program that has a 'pipe' mode, in which you can use 
> stdin to send commands to the program. I found out that, when in pipe 
> mode and you are using the keyboard as input source you can do Ctrl-D to 
> 'signal' the program that you have finished typing your command. The 
> program parses and then performs the command, and it doesn't quit. It 
> quits after 'Quit\n' + Ctrl-D
> Now I want a python script to provide the input, how do i do that? I now 
> use popen to be able to write to the program's stdin (p_stdin)
> I noticed that when i do a p_stdin.close() it acts as a 'ctrl-d' in that 
> the program recognizes the signal to process the command, but then I 
> cannot use p_stdin anymore to do p_stdin.write(...)

You might want to check the pty module in the Standard Library, and/or 
Pexpect (http://pexpect.sf.net/)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Put a file on an ftp server over ssl

2005-05-11 Thread Lars
Daniel,

Why don't you just use the 'sftp' command line program, it's available
for all unixes and I bet you can find a build for windows to? Then you
could just do an os.system(..) and be done with it.

Cheers!
Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Problem building extension under Cygwin (ImportError: Bad address)

2006-05-04 Thread Lars
Hi,

I have problems building a simple handcoded C-extension (hello.c) with
Cygwin and gcc3.4.4. I hope somebody has encountered the same problem
before, and has some advice.

The extension works just fine with Linux:

gcc -c hello.c -I/usr/local/include/python2.4/
ld -shared hello.o -o hello.so -L /usr/local/lib/ -lpython2.4 -lc
python -c'import hello;q = hello.message("Lars");print q'
Hello, Lars

But doing a similar compile under Cygwin doesn't work so well:
(same options, but the output is called hello.dll and the directories
are a bit different)

$ python -c"import hello"
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: Bad address

btw:
hello.c is from "Programming Python 2nd ed." by Mark Lutz. It's
published by O'Reilly. The code can be downloaded from:
http://examples.oreilly.com/python2/Examples.zip .
hello.c is in the directory PP2E\Integrate\Extend\Hello.


-Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem building extension under Cygwin (ImportError: Bad address)

2006-05-04 Thread Lars
Thanks Jason, it works now.

There seems to be some sort of issue with ld in cygwin when compiling
shared libraries (e.g. DLL's).
This worked on my Cygwin installation also:

--
gcc hello.c -I/usr/include/python2.4/ -L/usr/lib/python2.4/config/
-lpython2.4 -shared -o hello.dll
python hellouse.py
(gives the right answer)


But first compiling hello.c with gcc, then linking it with gnu-ld just
won't work. I only really need to compile one C-file to a shared
library so it doesn't matter so much for me. But bigger projects will
have a problem..

--
gcc -c hello.c -I/usr/include/python2.4/
ld -shared hello.o -o hello.so -L /usr/lib/python2.4/config -lpython2.4
-lc
python hellouse.py
Traceback (most recent call last):
  File "hellouse.py", line 1, in ?
import hello
ImportError: Bad address
---

-Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem building extension under Cygwin (ImportError: Bad address)

2006-05-04 Thread Lars
Great!
Thanks for the advice.

Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Split entries from LDAP

2008-10-11 Thread Lars
Hi
I got some programming experience and I recently started looking into
Python. I've read much of the tutorial from 2.6 documentation. But it
was more interesting to get started on something I needed. I'm trying
to create a script that creates a variable list (just a txt file to be
included in bash scripts) with hosts from LDAP. The file will include
some static entries and the hosts based on 'cn', 'ipHostNumber' and I
might as well set the 'description' as commen,t when the list from
LDAP is created.
I got all the entries in the variable "raw_res" and I now got some
doubts on how to split each value up in every entry. Belove you can
see one of entries printed from the loop.
cn=world.dom.dk,ou=Hosts,o=Users,dc=dom,dc=dk', {'ipHostNumber':
['192.168.0.43'], 'cn': ['world.dom.dk'], 'description':
['Mail&webserver']})"

I've tried different things, but don't quite know to split the tuple.
The examples I've seen is with a nice clean list ("a", "b", "z"), and
mine is full of special characters and etc., so some direction would
be appreciated.


/Lars


--
#!/usr/bin/env python

import ldap, sys, ldif

# .: LDAP Connection Settings :.
server="NA"
username="NA"
passwd="NA"
basedn="NA"

try:
l = ldap.initialize(server)
l.protocol_version = ldap.VERSION3
l.simple_bind(username, passwd)
filter = '(objectClass=ipHost)'
attrs = ['cn','ipHostNumber','description']
raw_res = l.search_s( basedn, ldap.SCOPE_SUBTREE, filter, attrs )
except ldap.INVALID_CREDENTIALS:
print "Your username or password is incorrect."
sys.exit()
except ldap.LDAPError, e:
print e
sys.exit()

#print raw_res

for I in range(len(raw_res)):
print I, ": ",

l.unbind()
--
http://mail.python.org/mailman/listinfo/python-list


Call function from another class

2009-07-27 Thread Lars
Hi
I'm trying to make an simple image viewer in wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit. The
class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 39) creates a menu, where the function "def onRotate
(self,event):" (l. 43) is called. The slider appear in at 2nd window,
class rotationSlider(wx.Frame).
My problem is what to do, when the Okay button is pressed in the
"rotationSlider" frame. How to get the slider value to my main window
and how to call a function to do the rotation. I tried something with
a global variable, but it would make no difference regarding the
function problem. Amongst the other things I've tried is to bind the
event of the 2nd/slider window closing (l. 46), but no.
Python code at Pastebin: http://pastebin.com/m7c24ec34

So some help on Classes and etc., would be appreciated.

/Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Call function from another class

2009-07-27 Thread Lars
> If I'm not mistaken, in "doRotate" you should be able to refer to the
> to-be-closed dialog via
> self.frameRotate
>
> Now if you change the "sliderUpdate"-code to store that angle instead of
> just letting it fall out of scope, you could access that value through
> frameRotate:
>
> def sliderUpdate(self, event):
>         angle=self.slider.GetValue()
>         ROTATION_ANGLE=angle
>         self.angle = angle
>         self.Destroy()
>
> def doRotate(self,event):
>     """Rotating image"""
>     print self.frameRotate.angle

Thanks for replying. If Bind is used in "onRotate":
def onRotate(self,event):
   """Rotate image"""
   self.frameRotate = rotationSlider(parent=None, id=-1)
   self.Bind(wx.EVT_CLOSE,self.doRotate, self.frameRotate.Destroy)
   self.frameRotate.Show()

Then i get:
Traceback (most recent call last):
  File "viewer_sep.py", line 136, in onRotate
self.Bind(wx.EVT_CLOSE,self.doRotate, self.frameRotate.Destroy)
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/
_core.py", line 3629, in Bind
id  = source.GetId()
AttributeError: 'function' object has no attribute 'GetId'

My experience with ID is setting it to "-1".  So I'm not sure if it is
a wrong use of Bind or an wxPython error.
/Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Python mode: make emacs use existing *Python* frame, and not open a new one

2011-06-16 Thread Lars Bungum

Hi,

I am using python-mode to write python code in Emacs, and when I use the 
useful C-c C-c key combination to interpret the buffer, Emacs always 
opens another window inside the window I am using.


I prefer using Emacs split in two windows (one on each physical screen) 
where I program in one of them and use the Python interpreter in the 
other.  Is there a way I can tell Emacs to use the *Python* buffer in 
the Window that is already open instead of creating a new one?


Note: When I tried gnu.emacs.help it was suggested that it was a bug (as 
the only suggestion).  Is there a way to get around this?


--lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: [PyWart 1001] Inconsistencies between zipfile and tarfile APIs

2011-07-22 Thread Lars Gustäbel
On Thu, Jul 21, 2011 at 08:46:05PM -0700, rantingrick wrote:
> I may have found the mother of all inconsitency warts when comparing
> the zipfile and tarfile modules. Not only are the API's different, but
> the entry and exits are differnet AND zipfile/tarfile do not behave
> like proper file objects should.

There is a reason why these two APIs are different. When I wrote tarfile
zipfile had already been existing for maybe 8 years and I didn't like its
interface very much. So, I came up with a different one for tarfile that in my
opinion was more general and better suited the format and the kind of things I
wanted to do with it. In the meantime the zipfile API got a lot of attention
and some portions of tarfile's API were ported to zipfile.

> *COMMENT*
> As you can see, the tarfile modules exports an open function and
> zipfile does not. Actually i would prefer that neither export an open
> function and instead only expose a class for instantion.

So that is your preference.

> *COMMENT*
> Since a zipfile object is a file object then asking for the tf object
> after the object after the file is closed should show a proper
> message!

It is no file object.

> *COMMENT*
> Tarfile is missing the attribute "fp" and instead exposes a boolean
> "closed". This mismatching API is asinine! Both tarfile and zipfile
> should behave EXACTLY like file objects

No, they don't. Because they have not much in common with file objects. I am
not sure what you are trying to prove here. And although I must admit that you
have a point overall you seem to get the details wrong. If tarfile and zipfile
objects behave "EXACTLY" like file objects, what does the read() method return?
What does seek() do? And readline()?

What do you prove when you say that tarfile has no "fp" attribute? You're not
supposed to use the tarfile's internal file object, there is nothing productive
you could do with it.

> *COMMENT*
> As you can see, unlike tarfile zipfile cannot handle a passed path.

Hm, I don't know what you mean.

> zf.namelist() -> tf.getnames()
> zf.getinfo(name) -> tf.getmenber(name)
> zf.infolist() -> tf.getmembers()
> zf.printdir() -> tf.list()
> 
> *COMMENT*
> Would it have been too difficult to make these names match? Really?

As I already stated above, I didn't want to adopt the zipfile API because I
found it unsuitable. So I came up with an entirely new one. I thought that
being incompatible was better than using an API that did not fit exactly.

> *COMMENT*
> Note the inconsistencies in naming conventions of the zipinfo methods.
> 
> *COMMENT*
> Not only is modified time named different between zipinfo and tarinfo,
> they even return completely different values of time.

See above.

> It is very obvious that these modules need some consistency between
> not only themselves but also collectively. People, when emulating a
> file type always be sure to emulate the built-in python file type as
> closely as possible.

See above.

> PS: I will be posting more warts very soon. This stdlib is a gawd
> awful mess!

I do not agree. Although I come across one or two odd things myself from time
to time, I think the stdlib as a whole is great, usable and powerful.

The stdlib surely needs our attention. Instead of answering your post, I should
have been writing code and fixing bugs ...

-- 
Lars Gustäbel
l...@gustaebel.de

Seek simplicity, and distrust it.
(Alfred North Whitehead)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistencies between zipfile and tarfile APIs

2011-07-22 Thread Lars Gustäbel
On Thu, Jul 21, 2011 at 10:58:37PM -0700, rantingrick wrote:
> My hat is off to you Mr. Richardson. I've even considered creating my
> own clean versions of these two modules, because heck, it is not that
> difficult to do! However we must stop fixing these warts on a local
> level Corey. We MUST clean up this damn python stdlib once and for
> all.

One could get the impression that you are leading a grass-roots movement
fighting a big faceless corporation. Instead, what you're dealing with is this
warm and friendly Python community you could as well be a part of if you are a
reasonable guy and write good code.

> I am willing and you are willing; that's two people. However, can we
> convince the powers that be to upgrade these modules? Sure, if we get
> enough people shouting for it to happen they will notice. So come on
> people make your voices heard. Chime in and let the devs know we are
> ready to unite and tackle these problems in our stdlib.

Yeah, great. Please write code. Or a PEP.

> What this community needs (first and foremost) is some positive
> attitudes. If you don't want to write the code fine. But at least
> chime in and say... "Hey guys, that's a good idea! I would like to see
> some of these APIs cleaned up too. good luck! +1"

+1

> Now, even if we get one hundred people chanting... "Yes, Yes, Fix This
> Mess!"... i know Guido and company are going to frown because of
> backwards incompatibility. But let me tell you something people, the
> longer we put off these changes the more painful they are going to
> be.

And backwards compatibility is bad why? Tell me, what exactly is your view
towards this? Should there be none?

> Python 3000 would have been the perfect time to introduce a more
> intuitive and unified zip/tar archive module however that did not
> happen. So now we need to think about adding a duplicate module
> "archive.py" and deprecating zipfile.py and tarfile.py. We can remove
> the old modules when Python 4000 rolls out.
> 
> That's just step one people, we have a long way to go!

archive.py is no new idea. Unfortunately, to this day, nobody had the time to
come up with an implementation.

Let me say it again: less false pathos, more code. Please.

-- 
Lars Gustäbel
l...@gustaebel.de

To a man with a hammer, everything looks like a nail.
(Mark Twain)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: English Idiom in Unix: Directory Recursively

2011-05-21 Thread Lars Enderin
2011-05-21 10:32, Jonathan de Boyne Pollard skrev:
>> The supposed inefficiency of recursive implementations is based
>> largely on the properties of hardware that is now obsolete. With
>> modern processors there's no great efficiency hit. In some of the
>> smaller microcontrollers, it's true, you do have to worry about stack
>> overflow; but the ARM processors, for example, provide plenty of stack
>> space.
>>
>> In the microcontroller world, the big performance hits come from the
>> fact that the only available compilers are for C and sometimes C++.
>> (And nobody uses assembly language except for the very little jobs.)
>> The nature of the C language prevents compilers from doing
>> optimisations that are standard in compilers for high-level languages.
>> Most C compilers will, for example, always pass parameters on the
>> stack, despite the generous supply of registers available in newer
>> hardware.
>>
> However, some C compilers will *also* have one or more "go faster"
> calling conventions that pass parameters in registers, which can be
> employed.  Over in the PC world, such "go faster" calling conventions
> are even the default calling convention if no calling convention is
> explicitly specified, for some C and C++ compilers.
> 
>
> http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Compiler
> 
>
> http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Optlink
> 
>
> http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/function-calling-conventions.html#Watcall
> 

Please include attributions, in this case for Peter Moylan and rusi!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: English Idiom in Unix: Directory Recursively

2011-05-21 Thread Lars Enderin
2011-05-21 11:52, Lars Enderin skrev:
> 
> Please include attributions, in this case for Peter Moylan and rusi!

Just Peter Moylan, sorry!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: English Idiom in Unix: Directory Recursively

2011-05-21 Thread Lars Enderin
2011-05-21 11:54, Lars Enderin skrev:
> 2011-05-21 11:52, Lars Enderin skrev:
>>
>> Please include attributions, in this case for Peter Moylan and rusi!
> 
> Just Peter Moylan, sorry!

Ignore the above.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why no list as dict key?

2022-04-25 Thread Lars Liedtke
May I stupidly ask, why one would want to use an iterable (even 
immutable) as dict key?


I thought keys were meant to be something "singular". And yes you could 
also combine a string to be a key, and if you combine a string it would 
be somehow the same as a tuple. But anyways I still fail to see the 
application for that, which is most propably to ignorance rather than 
criticism.


Cheers

Lars


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 21.04.22 um 07:00 schrieb Chris Angelico:

On Thu, 21 Apr 2022 at 13:23, Abdur-Rahmaan Janhangeer
 wrote:

Assumes checking for object equality before inserting.
If they are they same, do we need different hashes?


The point of the hash is to find things that are equal. That's why
1234, 1234.0, and 0j+1234.0 all have the same hash.

If equality changes, the hash does too. It's certainly possible to
have the hash come from object identity, but then so must equality. If
you want that, it's easy to do - just create your own object for the
state, rather than using a list. But then you have to use the original
object to look things up, instead of matching by the data.

Hashes are simply a short-hand for equality. That's all.

ChrisA


--
https://mail.python.org/mailman/listinfo/python-list


Re: Why no list as dict key?

2022-04-25 Thread Lars Liedtke

Thx, didn't see it that way yet.


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 25.04.22 um 15:54 schrieb Peter J. Holzer:

On 2022-04-25 15:13:19 +0200, Lars Liedtke wrote:

May I stupidly ask, why one would want to use an iterable (even immutable)
as dict key?

A string is also an immutable iterable, so this is probably even the
most common case.

As for more complex data structures:

* Tuples or immutable dicts are a good fit if want to group records by
   subset of their attributes (think "group by" in SQL)

* Objects in general are often though of as units, even if they have
   composite values and you might want to look up something by that
   value.

 hp




--
https://mail.python.org/mailman/listinfo/python-list


Re: Python & nmap

2022-05-19 Thread Lars Liedtke

# scp "my_file" root@192.168.205.x/my_directory


Maybe it could be a good idea to look at Ansible for copying the Files 
to all the hosts, because that is one thing ansible is made for.


For the nmap part: Ansible does not have a module for that (sadly) but 
is very extensible, so if you start developing something like that in 
Python, you could as well write an ansible module and combine both, 
because Ansible itself is written in Python.


Cheers

Lars


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php


--
https://mail.python.org/mailman/listinfo/python-list


Re: Python & nmap

2022-05-20 Thread Lars Liedtke
Ansible has got a shell module, so you could run custom commands on all 
hosts. But it gets more difficult in parsing the output afterwards.



--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 19.05.22 um 21:16 schrieb ^Bart:
Maybe it could be a good idea to look at Ansible for copying the 
Files to all the hosts, because that is one thing ansible is made for.


I didn't know it... thanks to share it but... I should start to study 
it and I don't have not enought free time... but maybe in the future 
I'll do it! :)


For the nmap part: Ansible does not have a module for that (sadly) 
but is very extensible, so if you start developing something like 
that in Python, you could as well write an ansible module and combine 
both, because Ansible itself is written in Python.


Ah ok, maybe now I just start to write a bash script because I need to 
start this work asap, when I'll have one minute I'll try to move the 
script in Python and after it I could "upload" the work on Ansible! :)



Cheers

Lars


Thanks!
^Bart



--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Lars Liedtke


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 21.06.22 um 11:04 schrieb Chethan Kumar S:

I have a main process which makes use of different other modules. And these 
modules also use other modules. I need to log all the logs into single log 
file. Due to use of TimedRotatingFileHandler, my log behaves differently after 
midnight. I got to know why it is so but couldn't get how I can solve it.
Issue was because of serialization in logging when multiple processes are 
involved.


Could be unrelated and only a part of a solution, but if you are on a 
unixoid system, you could use logrotate, instead of 
TimedRotatingFileHandler. logfrotate ensures that the logging service 
does not realize, its logs have been rotated. So it can log as if 
nothing has happened.


I don't know, if that helps with your multiple processes, or is a 
solution at all.


Cheers

Lars


--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Lars Liedtke


The process that is writing the file must be told that rotation has 
happened for it to work.
Other wise all the logs keep being write to the original file via the 
FD that the process has.


logrotate's config include how to tell the process the log file needs 
reopening.



Thanks for clearing.

--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php


--
https://mail.python.org/mailman/listinfo/python-list


Re: why function throws an error?

2022-06-28 Thread Lars Liedtke

Hey,

Which error does it throw?
Could you please send the stacktrace as well?

Cheers

Lars


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 28.06.22 um 09:57 schrieb נתי שטרן:

 def add_route(self, route):
 #""" Add a route object, but do not change the :data:`Route.app`
 #attribute."""
 self.routes.append(route)
 self.router.add(route.rule, route.method, route, name=route.name
)
 #if DEBUG: route.prepare()
--
<https://netanel.ml>


--
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand nested loops

2022-08-05 Thread Lars Liedtke

Hello,

this looks to me like it might be a piece of homework, as it would be 
given by teachers or professors.


This list has got the rule, that members do not solve other's homework. 
Because very often homework is meant to sit down and think about it.


But maybe I interpreted that wrongly, so if you could try to formulate 
in words what this loop does, I or other people on this list, will be 
pleased to show you where you might have got things wrong and how it 
really works.


Cheers

Lars


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 05.08.22 um 09:34 schrieb ojomooluwatolami...@gmail.com:

Hello, I’m new to learning python and I stumbled upon a question nested loops. 
This is the question below. Can you please how they arrived at 9 as the answer. 
Thanks

var = 0
for i in range(3):
   for j in range(-2,-7,-2):
 var += 1
  print(var)

Sent from my iPhone


--
https://mail.python.org/mailman/listinfo/python-list


Re: Question about learning Python

2022-09-07 Thread Lars Liedtke

Hello and welcome,

the answer is a definitive "it depends" ;-)

Generally you do not need knowledge in C for learning Python.

But I'd say that it will not hurt to have some knowledge. Especially 
some packages use C-code to extend Python. But it seems to me that you 
are completely starting to learn how to program. Please correct me if I 
am wrong. So you can definitely learn how to program with learning 
Python and you can learn C afterwards if you need to.


Cheers

Lars


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 07.09.22 um 12:28 schrieb Maruful Islam:

I want to start learning python. I have a question about learning python.

Is learning C essential or not for learning python?


--
https://mail.python.org/mailman/listinfo/python-list


Re: problem downloading python

2022-09-14 Thread Lars Liedtke

Hello and welcome,

Sadly I don't know about Eset internet security, or why you do not get the 
choice of letting the installer do that, but you could try to add Python 
manually to your PATH like it is described in 
https://www.geeksforgeeks.org/how-to-add-python-to-windows-path/ .

But maybe some more windows savvy people than me might chime in to offer better 
advice ;-) .

Cheers

Lars


Lars Liedtke
Software Entwickler

[Tel.]
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 14.09.22 um 11:42 schrieb carlharrison:

Dear Sir or Madam,

I am working on a PC with windows 10 and use Eset internet security. I have
tried downloading  python 3.10.7 for windows. Using a tutorial I see that a
checkbox should appear called "Add python 3/7 to path" but this does not
appear whichever version I try to download. I wondered if Eset was stopping
this somehow and tried it with Eset switched off but the result is the same.
Can you help?

Best regards,

Carl Harrison.




--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace an instance method?

2022-09-18 Thread Lars Liedtke

Hey,

What has not been mentioned yet is simple delegation.

Often you want to rewrite a method, maybe have different (more or less) 
parameters and additionally keep the old methods for backwards compatibility. 
Or mark it as deprecated at a later point. So you could write the new method 
and change the old method to call the new method but with the parameters the 
new method expects. If you explain this in the docstrings as well. Then you do 
not need to actually replace the method.

Or you had a completely different use-case in mind, that I missed.

Cheers

Lars


Lars Liedtke
Software Entwickler

[Tel.]
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 16.09.22 um 22:55 schrieb Ralf M.:
I would like to replace a method of an instance, but don't know how to do it 
properly.

My first naive idea was

inst = SomeClass()
def new_method(self, param):
   # do something
   return whatever
inst.method = new_method

however that doesn't work: self isn't passed as first parameter to
the new inst.method, instead inst.method behaves like a static method.

I had a closer look at the decorators classmethod and staticmethod.
Unfortunetely I couldn't find a decorator / function "instancemethod"
that turns a normal function into an instancemethod.

The classmethod documentation contains a reference to the standard
type hierarchie, and there is an explanation that an instancemethod
is sort of a dynamically created wrapper around a function, which
is accessable as __func__.
So I modified the last line of the example above to

inst.method.__func__ = new_method

but got told that __func__ is read only.

I found some information about methods in the Descriptor HowTo Guide,
but it's about how it works internally and doesn't tell how to solve
my problem (at least it doesn't tell me).

Now I'm running out of ideas what to try next or what sections of the
documentation to read next.

Any ideas / pointers?

Ralf M.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Superclass static method name from subclass

2022-11-11 Thread Lars Liedtke

yes,

just use SubClass.foo

at least this works for me:

class SuperClass:
   @staticmethod
   def test():
   print("yay")

class SubClass(SuperClass):

   def __init__(self):
   super().__init__()
   SubClass.test()

subclass = SubClass()

Output:

python3.11 test.py
yay


Cheers

Lars


Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 11.11.22 um 17:21 schrieb Ian Pilcher:
Is it possible to access the name of a superclass static method, when
defining a subclass attribute, without specifically naming the super-
class?

Contrived example:

 class SuperClass(object):
 @staticmethod
 def foo():
 pass

 class SubClass(SuperClass):
 bar = SuperClass.foo
   ^^

Is there a way to do this without specifically naming 'SuperClass'?

--
https://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 double quote behavior

2022-12-13 Thread Lars Liedtke

Hey,

this might be not the answer you are searching for at all, and it is only a 
mitigation. But as far as I know, sqlalchemy (and other ORMs) do that for you. 
I am mention sqlalchemy, because it has got a query builder as well. So you 
don't have to change your DB-Layer to full ORM, but you could let it build the 
queries for you.

Of course, I know that this would mean a dependency and additional complexity. 
I just could not leave it unmentioned ;-)

Cheers

Lars


Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 13.12.22 um 01:41 schrieb John K. Parejko:

Asking here before I file an improvement request issue on the python GitHub:

sqlite has a known misfeature with double-quoted strings, whereby they will be 
interpreted as string literals if they don’t match a valid identifier [1]. The 
note in the sqlite docs describe a way to disable this misfeature at compile 
time or by calling an `sqlite3_db_config` C-function, but I don’t see any way 
to do that in the python sqlite library [2].

Am I missing a way to manage this setting, or is it not available within 
python? This would be very useful to enable, so that python’s sqlite library 
will treat queries more like standard sql, instead of this particular version 
of MySQL. I was just burned by this, where some tests I’d written against an 
sqlite database did not fail in the way that they “should” have, because of 
this double-quoted string issue.

It doesn’t look like `sqlite3_db_config` is used within the python sqlite3 
codebase at all, so this might not be a trivial change? I only see two 
references to it in the cpython github.

Thank you in advance for any suggestions,
John

1: https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted
2: https://docs.python.org/3/library/sqlite3.html

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to enter escape character in a positional string argument from the command line?

2022-12-21 Thread Lars Liedtke

Or you could have "native" bash ($SHELL) with WSL. But I assume not everyone is 
using it.

Cheers

Lars


Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 21.12.22 um 13:15 schrieb Albert-Jan Roskam:

  On Dec 21, 2022 06:01, Chris Angelico 
<mailto:ros...@gmail.com> wrote:

On Wed, 21 Dec 2022 at 15:28, Jach Feng 
<mailto:jf...@ms4.hinet.net> wrote:
> That's what I am taking this path under Windows now, the ultimate
solution before Windows has shell similar to bash:-)

Technically, Windows DOES have a shell similar to bash. It's called
bash. :) The trouble is, most people use cmd.exe instead.

  =
  I use Git Bash quite a lot: https://gitforwindows.org/
  Is that the one you're referring to?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Fast lookup of bulky "table"

2023-01-15 Thread Lars Liedtke

Hey,

before you start optimizing. I would suggest, that you measure response times and query 
times, data search times and so on. In order to save time, you have to know where you 
"loose" time.

Does your service really have to load the whole table at once? Yes that might 
lead to quicker response times on requests, but databases are often very good 
with caching themselves, so that the first request might be slower than 
following requests, with similar parameters. Do you use a database, or are you 
reading from a file? Are you maybe looping through your whole dataset on every 
request? Instead of asking for the specific data?

Before you start introducing a cache and its added complexity, do you really 
need that cache?

You are talking about saving microseconds, that sounds a bit as if you might be 
“overdoing” it. How many requests will you have in the future? At least in 
which magnitude and how quick do they have to be? You write about 1-4 seconds 
on your laptop. But that does not really tell you that much, because most 
probably the service will run on a server. I am not saying that you should get 
a server or a cloud-instance to test against, but to talk with your architect 
about that.

I totally understand your impulse to appear as good as can be, but you have to 
know where you really need to debug and optimize. It will not be advantageous 
for you, if you start to optimize for optimizing's sake. Additionally if you 
service is a PoC, optimizing now might be not the first thing you have to worry 
about, but about that you made everything as simple and readable as possible 
and that you do not spend too much time for just showing how it could work.

But of course, I do not know the tasks given to you and the expectations you 
have to fulfil. All I am trying to say is to reconsider where you really could 
improve and how far you have to improve.



Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 15.01.23 um 05:26 schrieb Dino:

Hello, I have built a PoC service in Python Flask for my work, and - now that 
the point is made - I need to make it a little more performant (to be honest, 
chances are that someone else will pick up from where I left off, and implement 
the same service from scratch in a different language (GoLang? .Net? Java?) but 
I am digressing).

Anyway, my Flask service initializes by loading a big "table" of 100k rows and 
40 columns or so (memory footprint: order of 300 Mb) and then accepts queries through a 
REST endpoint. Columns are strings, enums, and numbers. Once initialized, the table is 
read only. The endpoint will parse the query and match it against column values 
(equality, inequality, greater than, etc.) Finally, it will return a (JSON) list of all 
rows that satisfy all conditions in the query.

As you can imagine, this is not very performant in its current form, but 
performance was not the point of the PoC - at least initially.

Before I deliver the PoC to a more experienced software architect who will look 
at my code, though, I wouldn't mind to look a bit less lame and do something 
about performance in my own code first, possibly by bringing the average time 
for queries down from where it is now (order of 1 to 4 seconds per query on my 
laptop) to 1 or 2 milliseconds on average).

To be honest, I was already able to bring the time down to a handful of microseconds 
thanks to a rudimentary cache that will associate the "signature" of a query to 
its result, and serve it the next time the same query is received, but this may not be 
good enough: 1) queries might be many and very different from one another each time, AND 
2) I am not sure the server will have a ton of RAM if/when this thing - or whatever is 
derived from it - is placed into production.

How can I make my queries generally more performant, ideally also in case of a 
new query?

Here's what I have been considering:

1. making my cache more "modular", i.e. cache the result of certain (wide) 
queries. When a complex query comes in, I may be able to restrict my search to a subset 
of the rows (as determined by a previously cached partial query). This should keep the 
memory footprint under control.

2. Load my data into a numpy.array and use numpy.array operations to sl

Re: 转发: How to exit program with custom code and custom message?

2023-03-13 Thread Lars Liedtke

I totally understand your reasoning here, but in some way it follows the unix 
philosophy: Do only one thing, but do that good.

And exiting is something different from printing to STDOUT or STDERR. Yes 
sometimes you want to print something before exiting. But then you should do 
that explicitly and to the output you want and not implicitly rely on 
adfdtitional parameters of exit. Yes, not all functions work this way. But that 
does not mean they shouln't ;-)

Cheers

Lars

On 13.03.23 11:18, scruel tao wrote:

Chris:


It doesn't actually take a list of arguments; the square brackets


indicate that arg is optional here.

Oh, I see, it seems that I mistunderstood the document.



but for anything more complicated, just print and then exit.
It's worth noting, by the way, that sys.exit("error message") will
print that to STDERR, not to STDOUT, which mean that the equivalent
is:



Yes, I know, but don’t you think if `sys.exit` can take more parameters and 
have a default output channel selection strategy will be better?
Thanks.





Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php



--
https://mail.python.org/mailman/listinfo/python-list


Re: for a 'good python'

2023-04-13 Thread Lars Liedtke




Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de<mailto:l...@solute.de>


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de <http://www.solute.de/>
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 13.04.23 um 00:21 schrieb jak:
Barry ha scritto:



On 12 Apr 2023, at 18:10, jak <mailto:nos...@please.ty> wrote:
Hi everyone,
some time ago I wrote a class to determine if an ipv4 address belonged
to a subnet. Seldom using python I'm pretty sure it's not written in
'good python' nor too portable. Could you give me some advice to make it
better?

class calcip:
   def __init__(self, psubnet: str):
   ssubnet, scidr = psubnet.replace(' ', '').split('/')
   subnet = int.from_bytes(tuple(
 map(lambda n: (int(n)), ssubnet.split('.'))),
   'big')
   cidr = int(scidr)
   mask = ((2 ** cidr) - 1) << (32 - cidr)
   self.__network = subnet & mask
   self.__wildcard = ~mask & 0x
   self.__broadcast = (subnet | self.__wildcard) & 0x
   self.__tsubnet = tuple(subnet.to_bytes(4, 'big'))
   self.__tnetwork = tuple(self.__network.to_bytes(4, 'big'))
   self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big'))
   self.__tmask = tuple(mask.to_bytes(4, 'big'))
   self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big'))
   self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big'))
   self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big'))

   @staticmethod
   def __to_str(val: tuple):
   return '.'.join(str(v) for v in val)

   @property
   def subnet(self):
   return self.__to_str(self.__tsubnet)

   @property
   def network(self):
   return self.__to_str(self.__tnetwork)

   @property
   def broadcast(self):
   return self.__to_str(self.__tbroadcast)

   @property
   def mask(self):
   return self.__to_str(self.__tmask)

   @property
   def wildcard(self):
   return self.__to_str(self.__twildcard)

   @property
   def host_min(self):
   return self.__to_str(self.__host_min)

   @property
   def host_max(self):
   return self.__to_str(self.__host_max)

   @property
   def hosts_num(self):
   return self.__wildcard - 1

   @property
   def net_class(self):
   tst = (self.__tnetwork[0] & 0xf0) >> 4
   if (tst & 0x8) == 0:
   clx = 'A'
   elif (tst & 0xc) == 0x8:
   clx = 'B'
   elif (tst & 0xe) == 0xc:
   clx = 'C'
   elif (tst & 0xf) == 0xe:
   clx = 'D'
   elif (tst & 0xf) == 0xf:
   clx = 'E'
   return clx

   def __contains__(self, item):
   ret = True
   row_hdr = None
   try:
   row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), 
item.split('.'))), 'big')
   except:
   ret = False
   if ret:
   if not self.__network < row_hdr < self.__broadcast:
   ret = False
   return ret


def main():
   sn = calcip('10.0.0.0/26')

   print(f"subnet: {sn.subnet}")
   print(f"network: {sn.network}")
   print(f"broadcast: {sn.broadcast}")
   print(f"mask: {sn.mask}")
   print(f"wildcard: {sn.wildcard}")
   print(f"host_min: {sn.host_min}")
   print(f"host_max: {sn.host_max}")
   print(f"Avaible hosts: {sn.hosts_num}")
   print(f"Class: {sn.net_class}")

   tst_hdr = '10.0.0.31'
   is_not = 'is '
   if not tst_hdr in sn:
   is_not = 'is NOT '
   print("hdr %s %sin range %s - %s" %
 (tst_hdr, is_not, sn.host_min, sn.host_max))

if __name__ == '__main__':
   main()

There is this https://docs.python.org/3/howto/ipaddress.html if you just want a 
solution.

Or are you after code review feedback?

Barry

--
https://mail.python.org/mailman/listinfo/python-list


Thank you too. I had seen this library but I always try not to use
libraries outside the standard ones. Now I don't remember why I was
convinced that this wasn't part of it, perhaps because it was like that
at the time or because I got confused. Only now I realized that it is
not necessary to install it. Now I'm considering whether to use
'ipaddress' or 'socket'. What is certain is that this one you have
suggested is really comfortable. Thanks again for the report.

Unless I am not mistakes, ipadress is "standard" because it is in the standard 
library
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pip standard error warning about dependency resolver

2021-02-24 Thread Lars Liedtke
I understand your problem and I know that sometimes it is not possible
to do it differently. But as far as my understanding goes, your backend
operations should not die on outputs on stderr. I understand that is
what return values are for and as long as the return value is 0
everything went without error, even though there might be output on stderr.

That said. As far as I know you could try the commandline option for
using the new resolver explicitly. I don't know if there is an option
for "silent"

Cheers

Lars

Am 23.02.21 um 17:48 schrieb adam@gmail.com:
> I started seeing this sometimes from pip:
>
> After October 2020 you may experience errors when installing or updating 
> packages. This is because pip will change the way that it resolves dependency 
> conflicts.
>
> Yeah, sure, that's something to consider. We seem fine with the new resolver. 
> Is there a way to suppress it? We have some back end operations that fail 
> when we get output on standard error, and they're dying from that notice.

-- 
---
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: memory consumption

2021-03-29 Thread Lars Liedtke
Hello Alexej,

May I stupidly ask, why you care about that in general? Please don't get
me wrong I don't want to criticize you, this is rather meant to be a
(thought) provoking question.
Normally your OS-Kernel and the Python-Interpreter get along pretty well
and whenthere is free memory to be had, or not the necessity to release
allocated memory then why force this? Python will release memory when
needed by running the gc.

Have you tried running your task over all the data you have? Did it
crash your system or prevent other processes from having enough memory?
If not: why care?

I know that there can be (good) reasons to care, but as long as your
tasks run fine, without clogging your system, in my opinion there might
be nothing to worry about.

Cheers

Lars

Am 29.03.21 um 12:12 schrieb Alexey:
> Hello everyone!
> I'm experiencing problems with memory consumption.
>
> I have a class which is doing ETL job. What`s happening inside:
>  - fetching existing objects from DB via SQLAchemy
>  - iterate over raw data
>  - create new/update existing objects
>  - commit changes
>
> Before processing data I create internal cache(dictionary) and store all 
> existing objects in it.
> Every 1 items I do bulk insert and flush. At the end I run commit command.
>
> Problem. Before executing, my interpreter process weighs ~100Mb, after first 
> run memory increases up to 500Mb
> and after second run it weighs 1Gb. If I will continue to run this class, 
> memory wont increase, so I think
> it's not a memory leak, but rather Python wont release allocated memory back 
> to OS. Maybe I'm wrong.
>
> What I tried after executing:
>  - gc.collect()
>  - created snapshots with tracemalloc and searched for some garbage, diff = 
>smapshot_before_run - smapshot_after_run
>  - searched for links with "objgraph" library to internal cache(dictionary 
>containing elements from DB)
>  - cleared the cache(dictionary)
>  - db.session.expire_all()
>
> This class is a periodic celery task. So when each worker executes this class 
> at least two times,
> all celery workers need 1Gb of RAM. Before celery there was a cron script and 
> this class was executed via API call
> and the problem was the same. So no matter how I run, interpreter consumes 
> 1Gb of RAM after two runs.
>
> I see few solutions to this problem
> 1. Execute this class in separate process. But I had few errors when the same 
> SQLAlchemy connection being shared
> between different processes.
> 2. Restart celery worker after executing this task by throwing exception.
> 3. Use separate queue for such tasks, but then worker will stay idle most of 
> the time.
> All this is looks like a crutch. Do I have any other options ?
>
> I'm using:
> Python - 3.6.13
> Celery - 4.1.0
> Flask-RESTful - 0.3.6
> Flask-SQLAlchemy - 2.3.2
>
> Thanks in advance!

-- 
---
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Create a contact book

2021-10-26 Thread Lars Liedtke
😂
> Here at Homeworks Anonymous, the first step is admitting that what you
> have is a homework problem. :) 
>
> ChrisA

-- 
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Call julia from Python: which package?

2021-12-17 Thread Lars Liedtke
Additionally I'd like to ask, if you e.g. used pandas and numpy before
you make the effort of rewriting everything.

Yes python is slower than compiled languages, but especially with numpy
you can make use of compiled code underneath.

Of course this could mean rewriting some existing code but staying in
python.

If you have done all of that or there are other impediments, then of
course no one will hold you back.

Am 17.12.21 um 16:12 schrieb Dan Stromberg:
> On Fri, Dec 17, 2021 at 7:02 AM Albert-Jan Roskam 
> wrote:
>
>> Hi,
>>
>> I have a Python program that uses Tkinter for its GUI. It's rather slow so
>> I hope to replace many or all of the non-GUI parts by Julia code. Has
>> anybody experience with this? Any packages you can recommend? I found three
>> alternatives:
>>
>> * https://pyjulia.readthedocs.io/en/latest/usage.html#
>> * https://pypi.org/project/juliacall/
>> * https://github.com/JuliaPy/PyCall.jl
>>
>> Thanks in advance!
>>
> I have zero Julia experience.
>
> I thought I would share this though:
> https://stromberg.dnsalias.org/~strombrg/speeding-python/
>
> Even if you go the Julia route, it's probably still best to profile your
> Python code to identify the slow ("hot") spots, and rewrite only them.

-- 
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-10 Thread Lars Liedtke
I think this is more a thing of apporach. Nginx is quite simple to 
install and a config doing nothing else than redirecting https to https 
and proxying requests to a service (whichever tat is, in your case 
gunicorn) can become a nobrainer. That is what it became for me. 
Additionally the config for only this functionality are less than 10. So 
it's may seem complicated at first, but is way less oncxe you got used 
to it.


Cheers

Lars

Am 08.01.22 um 17:25 schrieb Skip Montanaro:

Thanks all. I was hoping to get away without something more
sophisticated like NGINX. This is just a piddly little archive of an
old mailing list running on a single-core Ubuntu VM somewhere on the
East Coast. Speed is not a real requirement. Load balancing seemed
like overkill to me. Still, I guess if it has to be, then it has to
be.

Skip


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-10 Thread Lars Liedtke

server {
   listen [::]:80;
   listen 80;


   server_name api.familie-liedtke.net;

   location / {
   return 301 https://$host$request_uri;
   }

   include /usr/local/etc/nginx/include/letsencrypt.conf;
}

server {
   listen 443 ssl http2;
   listen [::]:443 ssl http2;

   server_name api.familie-liedtke.net;

   ssl_certificate 
/usr/local/etc/ssl/certs/api.familie-liedtke.net/fullchain.pem;
   ssl_certificate_key 
/usr/local/etc/ssl/certs/api.familie-liedtke.net/privkey.pem;


   root /var/www/api;

   location /weather/{
   access_log /var/log/nginx/weather-access.log;
   include uwsgi_params;
   rewrite ^/weather(/.*)$ $1 break;
   uwsgi_pass unix:///tmp/uwsgi.sock;
   }

   include /usr/local/etc/nginx/include/ssl.conf;
}

This is my config for a flask app on uwsgi. granted it is a bit more 
than the 10 lines I said. But there is not much sophistication to it.


Am 08.01.22 um 17:25 schrieb Skip Montanaro:

Thanks all. I was hoping to get away without something more
sophisticated like NGINX. This is just a piddly little archive of an
old mailing list running on a single-core Ubuntu VM somewhere on the
East Coast. Speed is not a real requirement. Load balancing seemed
like overkill to me. Still, I guess if it has to be, then it has to
be.

Skip


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why dict.setdefault() has value as optional?

2022-02-02 Thread Lars Liedtke

This is a quite philosophical queston if you look at it in general:
"What value do you give a variable, that is not set?"

You are right, at first it seems strange to have a default of None. But 
how do you want to signal that no default is set yet? Especially if you 
think of a dict that can have multiple keys with each different values 
of different types?


Have fun in the rabbithole ;-)

Cheers

Lars

Am 02.02.22 um 13:54 schrieb Marco Sulla:

Just out of curiosity: why dict.setdefault() has the default parameter
that well, has a default value (None)? I used setdefault in the past,
but I always specified a value. What's the use case of setting None by
default?


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Lars Liedtke
Each Browser is doing it differently and even Windows or 
Linux-Desktopmanagers (NetworkManager).


I have had cases, where one tool told me I had Internet and another one 
I hadn't.


So What Chris Angelico wrote is propably the best way, ping e.g. Google, 
do a DNS lookup and try http for Status 200. Each with its own 
Errorhandling and if you have got all three, then it is propable that 
you have "Internet".


Cheers

Lars

Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer:

Popular browsers tell: No internet connection detected. A function that
goes in the same sense. Unless they too are pinging Google.com to check ...

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://www.pythonkitchen.com>
github <https://github.com/Abdur-RahmaanJ>
Mauritius


On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico  wrote:


On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
 wrote:

Greetings,

Using the standard library or 3rd party libraries, what's the
best way to check if there is internet? Checking if google.com
is reachable is good but I wonder if there is a more native,
protocol-oriented
way of knowing?


What do you mean by "if there is internet"? How low a level of
connection do you want to test? You could ping an IP address that you
know and can guarantee will respond. You could attempt a DNS lookup.
You could try an HTTP request. Each one can fail in different ways,
for different reasons. It's best to test what you actually care about.


Even this URL recommends checking if a domain is up as a way to check for
internet connectivity:


https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits

That talks about a misconfigured proxy as being the most likely cause.
Is that something you're trying to test for?

There is no single concept of "there is internet". (Other than, in a
trivial sense, that the internet does exist.) What you need to know is
"can I use the internet?", and ultimately, that depends on what you
need it to do.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Lars Liedtke
P.S.: for ping a startingpoint can be icmplib, for dns dnspython and for 
http requests. But consider as well if you want to check for IPv4 and/or 
IPv6 Connectivity.


Am 07.02.22 um 13:47 schrieb Lars Liedtke:
Each Browser is doing it differently and even Windows or 
Linux-Desktopmanagers (NetworkManager).


I have had cases, where one tool told me I had Internet and another 
one I hadn't.


So What Chris Angelico wrote is propably the best way, ping e.g. 
Google, do a DNS lookup and try http for Status 200. Each with its own 
Errorhandling and if you have got all three, then it is propable that 
you have "Internet".


Cheers

Lars

Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer:

Popular browsers tell: No internet connection detected. A function that
goes in the same sense. Unless they too are pinging Google.com to 
check ...


Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://www.pythonkitchen.com>
github <https://github.com/Abdur-RahmaanJ>
Mauritius


On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico  wrote:


On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
 wrote:

Greetings,

Using the standard library or 3rd party libraries, what's the
best way to check if there is internet? Checking if google.com
is reachable is good but I wonder if there is a more native,
protocol-oriented
way of knowing?


What do you mean by "if there is internet"? How low a level of
connection do you want to test? You could ping an IP address that you
know and can guarantee will respond. You could attempt a DNS lookup.
You could try an HTTP request. Each one can fail in different ways,
for different reasons. It's best to test what you actually care about.

Even this URL recommends checking if a domain is up as a way to 
check for

internet connectivity:

https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits 



That talks about a misconfigured proxy as being the most likely cause.
Is that something you're trying to test for?

There is no single concept of "there is internet". (Other than, in a
trivial sense, that the internet does exist.) What you need to know is
"can I use the internet?", and ultimately, that depends on what you
need it to do.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


How do you log in your projects?

2022-02-08 Thread Lars Liedtke

Hello,

inspired by this thread 
https://mail.python.org/pipermail/python-list/2022-February/905167.html 
I finally came around to send in this question.


I know how to use python logging generally. Being on the DevOps-Side of 
things at the moment, I naturally began liking to run tools, which not 
only have logging, but also have different levels of logging 
configurable, because often when you run a couple of different services 
and software projects, logging is often the first help you turn to, and 
sometimes it is the only way to know what is going on. Not that the code 
of most (FLOSS) software is not available, but you simply do not have 
the time to read into the code of every piece of software you run.


So of course I want to write software on my own, if I have to or wpuld 
like to, that has got a decent amount of logging. But how often to 
actually log things? Of course the obvious answer is "it depends".


So how do you do your logging?
- On a line per line basis? on a function/method basis?
- Do you use decorators to mark beginnings and ends of methods/functions 
in log files?
- Which kind of variable contents do you write into your logfiles? Of 
course you shouldn't leak secrets...

- How do you decide, which kind of log message goes into which level?
- How do you prevent logging cluttering your actual code?

Maybe there are some questions I forgot, so please feel free to add 
whatever you think might help finding the best way of logging (tm)


Cheers

Lars

--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-14 Thread Lars Liedtke

Additionally, which datatype would you expect them to be returned in?

One could argument for int or float (Decimal?),  both could be valid 
datatypes, depending on how exact you might want them, while the second 
is the time base of SI units.


Cheers
Lars


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: l...@solute.de


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 14.04.22 um 17:01 schrieb Paul Bryan:

I think because minutes and hours can easily be composed by multiplying
seconds. days is separate because you cannot compose days from seconds;
leap seconds are applied to days at various times, due to
irregularities in the Earth's rotation.

On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote:

"Loris Bennett"  writes:


Hi,

With Python 3.9.2 I get

   $ import datetime
   $ s = "1-00:01:01"
   $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
   $ d = datetime.timedelta(days=t.day, hours=t.hour,
minutes=t.minute, seconds=t.second)
   $ d.days
   1
   $ d.seconds
   61
   $ d.minutes
   AttributeError: 'datetime.timedelta' object has no attribute
'minutes'

Is there a particular reason why there are no attributes 'minutes'
and
'hours and the attribute 'seconds' encompasses is the entire
fractional
day?

That should read:

   Is there a particular reason why there are no attributes 'minutes'
and
   'hours' and the attribute 'seconds' encompasses the entire
fractional
   day?


Cheers,

Loris

--
Dr. Loris Bennett (Herr/Mr)
ZEDAT, Freie Universität Berlin Email
loris.benn...@fu-berlin.de




--
https://mail.python.org/mailman/listinfo/python-list


Re: Nufox : Xul + Python

2005-10-01 Thread Lars Heuer
Hi,

> Oops:

> http://artyprog.noip.org:8080


Again Oops:  :))

http://artyprog.no-ip.org:8080

Best regards,
Lars
-- 
http://semagia.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.4: tarfile tell() and seek() seem to be broeken

2005-06-30 Thread Lars Gustäbel
On Thu, 02 Jun 2005 19:52:24 +0200, N. Volbers wrote:

> Thanks for taking care of it ;-)

I submitted patch #1230446 today which ought to fix the problem.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: psp & php integration

2005-07-26 Thread Lars Heuer
Hi Jon,

[ PHP / Python ]
> If not, is there any other way in Python (or PHP) to achieve this?

I'm not sure if it helps, but here is package that integrates the
Python into PHP:

http://www.csh.rit.edu/~jon/projects/pip/


Best regards,
Lars
-- 
http://semagia.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with tarfile.open and tar.bz2

2005-08-28 Thread Lars Gustäbel
On Fri, 26 Aug 2005 09:05:29 -0700, justin.vanwinkle wrote:

> Hello everyone,
> 
> I need some tar functionality for my program.  Currently the following
> code properly displays tar archives, and tar.gz archives.  However, it
> chokes on tar.bz2 archives with the following error:
> 
>   File "mail_filter.py", line 262, in extract_archive
> tar_archive = tarfile.open('', 'r', fileobj)
>   File "/usr/lib/python2.3/tarfile.py", line 900, in open
> return func(name, "r", fileobj)
>   File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open
> raise ValueError, "no support for external file objects"
> ValueError: no support for external file objects

The problem here is that the bz2.BZ2File class that tarfile.py uses to
access tar.bz2 files has no support for an external file-object argument.
In contrast to gzip.GzipFile, it works solely on real files.
This limitation is somewhat annoying, but so far no one took the trouble
changing the bz2 module.

If your program does not rely on random access to the tar.bz2 file, you
can still use the "r|bz2" stream mode:

tar_archive = tarfile.open(mode="r|bz2", fileobj=StringIO.StringIO(attach))
for tarinfo in tar_archive:
print tarinfo.name
print tar_archive.extractfile(tarinfo).read()
tar_archive.close()

-- 
Lars Gustäbel
[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change date format

2005-08-31 Thread Lars Gustäbel
[Xah Lee]
> Apache by default uses the following format for date:
> 30/Aug/2005
>
> is there a module that turn this directly into mmdd?

Use time.strptime() and time.strftime().

Not a single occurrence of the f**k word. You're making progress. Keep it up!

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Truth is the invention of a liar.
(Anonymous)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: determine if os.system() is done

2005-09-07 Thread Lars Gustäbel
[Fredrik Lundh]
> han har försökt, men hans tourette tog överhanden:

IMHO it's more likely an Asperger's syndrome.

http://en.wikipedia.org/wiki/Asperger_Syndrome

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Any sufficiently advanced technology is indistinguishable
from magic.
(Arthur C. Clarke)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sys.stdin.read question

2004-12-07 Thread Lars Tengnagel
Hej Caleb and others

I've been strugling with the same problem where i try to use popen3 to run a 
program. If I use a piped commandline
the program can read the file without problems but in the IDLE and with 
popen it comes with an error.
I haven't been able to read the stdin either so the problem so far is 
unsolved for my point.
But the newline command would explain my problems with the program.
Can it be a problem under windows since I'm using XP and the winpython

Hopefully Lars

"Caleb Hattingh" <[EMAIL PROTECTED]> skrev i en meddelelse 
news:[EMAIL PROTECTED]
> It runs properly in a shell (bash), but on another matter:
>
> '>>> r=sys.stdin.read(1)
> g
> '>>> r
> 'g'
> '>>> r=sys.stdin.read(5)
> 1234567890
> '>>> r
> '\n1234'
> '>>>
>
> What exactly happened to my 1234567890?  I understand that I am only 
> taking 5 characters, but where does the newline (\n) come from?  Is that a 
> remnant from when I terminated the previous 'g' input?
>
> Thanks
> Caleb
>
>
> On Tue, 07 Dec 2004 23:36:56 -0500, Caleb Hattingh <[EMAIL PROTECTED]> 
> wrote:
>
>> Hi
>>
>> You are probably typing this within IDLE.  Try it after starting python 
>> in a shell like DOS or Bash.  Should work then (works for me, and I also 
>> get the AttributeError in IDLE.
>>
>> Thanks
>> Caleb
>>
>> On Tue, 07 Dec 2004 21:15:51 GMT, It's me <[EMAIL PROTECTED]> wrote:
>>
>>> Why do I get an "AttributeError: read" message when I do:
>>>
>>> import sys
>>> r=sys.stdin.read()
>>>
>>> ??
>>>
>>> I've tried:
>>>
>>> r=sys.stdin.read(80)
>>> r=sys.stdin.read(1)
>>>
>>> same error message.
>>>
>>> I couldn't find any reference to this function in my Python book (they 
>>> have
>>> the stdout but not in).
>>>
>>> Some sample code I saw uses this function in the same manner I am and 
>>> so I
>>> am assuming this is the correct syntax?
>>>
>>> Or is this a bug in Python 2.4?
>>>
>>> --
>>> It's me
>>>
>>>
>>
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


converting textobject to name of other object.

2004-12-07 Thread Lars Tengnagel
I'm trying to use the matrix variable to collect a matrix in the file 
MatrixInfo which contains a lot of different matrices. Yhe commented line is 
the problem.
HOW ???

import re
import MatrixInfo

class Diff:
def __init__(self,filobj,matrix='pam250',begin=0,end='none'):
self.fil = filobj
self.begin = begin
self.end = end
if matrix in MatrixInfo.available_matrices:
##self.matrix =MatrixInfo.matrix
self.matrix= MatrixInfo.pam250
else print "matrix don't exist %s" %matrix
self.seqnr=0
self.basenr=0
self.dict = {}

Thanks Lars 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Path problem

2004-12-12 Thread Lars Yencken
Hi Binu,
On 13/12/2004, at 4:11 PM, Binu K S wrote:
This should get you the module's path:
import sys
sys.modules['rpy'].__file__
Unfortunately it's not the rpy module itself whose path I'm looking 
for. It's the absolute path of my module that I've created.

If my script was called runRScript.py, and it was in the same directory 
as someScript.r, I'm only able to get it working if I run

python runRScript.py
from the same directory. In otherwords, I can't be in a child directory 
and run:

python ../runRScript.py
because runRScript depends internally on the file someScript.r, and 
can't find it.

I've found a pathconf module posted earlier to this group, which does 
half the job. Unfortunately, when I call get_rootdir() it returns 
'/usr/bin' instead of my project's root directory ;(

Lars
--
http://mail.python.org/mailman/listinfo/python-list


Path problem

2004-12-12 Thread Lars Yencken
Hello,
I'm working on a project where my python modules are using persistent 
files in the same directory. As an example, we're using rpy, so a piece 
of python code might read:

from rpy import *
rScript = 'myScript.r'
r.source(rScript)
Now the problem with this is that when I run this from the directory 
above, or any other directory than the directory containing the R 
script, this doesn't work, and understandably too.

Is there some easy way to get around this? I can't (and don't want to) 
hard code paths, since they'll be different on every workspace I check 
out from the repository.

If there's a way that I can get the directory of the module file 
itself, then that's all I need to fix this for good.

Thanks,
Lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: Path problem

2004-12-13 Thread Lars Yencken
On 13/12/2004, at 6:39 PM, Binu K S wrote:
sys.path[0] will contain the path to the script.
From the sys module documentation:
"As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to
invoke the Python interpreter. If the script directory is not
available (e.g. if the interpreter is invoked interactively or if the
script is read from standard input), path[0] is the empty string,
which directs Python to search modules in the current directory first.
Notice that the script directory is inserted before the entries
inserted as a result of PYTHONPATH."
Thanks, that's very helpful!!! That's fixed up a lot of scripts of mine 
already, since many rely on an additional R script.

As to finding the path to my project root, I've managed to get the 
other pathconf module going. Yay!

Thanks Binu and Limodou for your help.
Lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTML editor component?

2005-03-20 Thread Lars Heuer
Hi skol,

> Is there any HTML WYSIWYG editor component available for
> Python/wxPython? Thanks. 

There is wxMozilla: http://wxMozilla.sf.net/

Best regards,
Lars
-- 
http://semagia.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML editor component?

2005-03-20 Thread Lars Heuer
Hi skol,

>>> Is there any HTML WYSIWYG editor component available for
>>> Python/wxPython? Thanks.
>>
>> There is wxMozilla: http://wxMozilla.sf.net/

> Thanks for the tip. Looks like a very elaborate component.
> Is there anything simpler? I'd need just simple HTML editing
> with formatting (bold, italic), links, and tables. 

You can use wxHTML for showing HTML and wxTextCtrl with (if I remember
right) the wxTE_RICHEDIT flag for editing.
Or the Scintilla component that should work for simple bold, italic
and link formating.
Tables might be difficult, though.

If you'll like to see wxMozilla Editor in action you may take a look
at http://www.eclass.net/

Best regards,
Lars
-- 
http://semagia.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-11 Thread Lars Gustäbel
On Thu, Feb 11, 2016 at 04:41:43PM +, Ulli Horlacher wrote:
>   sfo = sock.makefile('r')
>   taro = tarfile.open(fileobj=sfo,mode='r|')
>   taro.extractall(path=edir)

What about using an iterator?

def myiter(tar):
for t in tar:
print "extracting", t.name
yield t

sfo = sock.makefile('r')
taro = tarfile.open(fileobj=sfo,mode='r|')
taro.extractall(members=myiter(taro),path=edir)

Cheers,

-- 
Lars Gustäbel
l...@gustaebel.de
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : read from a socket?

2016-02-12 Thread Lars Gustäbel
On Fri, Feb 12, 2016 at 09:35:40AM +0100, Antoon Pardon wrote:
> On 02/11/2016 06:27 PM, Lars Gustäbel wrote:
> > What about using an iterator?
> >
> > def myiter(tar):
> > for t in tar:
> > print "extracting", t.name
> > yield t
> >
> > sfo = sock.makefile('r')
> > taro = tarfile.open(fileobj=sfo,mode='r|')
> > taro.extractall(members=myiter(taro),path=edir)
> >
> The tarfile is already an iterator. Just do the following: for ti in
> taro: print "extracting", ti.name taro.extract(ti)

The extractall() method does a little bit more than just extract(), i.e.
setting directory mtimes, see
https://docs.python.org/3.5/library/tarfile.html#tarfile.TarFile.extractall

-- 
Lars Gustäbel
l...@gustaebel.de
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile : secure extract?

2016-02-12 Thread Lars Gustäbel
On Thu, Feb 11, 2016 at 11:24:01PM +, Ulli Horlacher wrote:
> In https://docs.python.org/2/library/tarfile.html there is a warning:
> 
>   Never extract archives from untrusted sources without prior inspection.
>   It is possible that files are created outside of path, e.g. members that
>   have absolute filenames starting with "/" or filenames with two dots
>   "..". 
> 
> My program has to extract tar archives from untrusted sources :-}

Read the discussion in this issue on why this might be a bad idea:
http://bugs.python.org/issue21109

-- 
Lars Gustäbel
l...@gustaebel.de
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: merits of Lisp vs Python

2006-12-13 Thread Lars Brinkhoff
Bill Atkins <[EMAIL PROTECTED]> writes:
> the macro is just a friendlier syntax for expressing an idea.

I like that phrase!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to determine if a certain PID is still running

2006-02-03 Thread Lars Gustäbel
On Thu, Feb 02, 2006 at 05:10:24PM -0800, David Hirschfield wrote:
> I'm launching a process via an os.spawnvp(os.P_NOWAIT,...) call.
> So now I have the pid of the process, and I want a way to see if that 
> process is complete.
> 
> I don't want to block on os.waitpid(), I just want a quick way to see if 
> the process I started is finished. I could popen("ps -p %d" % pid) and 
> see whether it's there anymore...but since pids get reused, there's the 
> chance (however remote) that I'd get a false positive, plus I don't 
> really like the idea of calling something non-pure-python to find out.

You could try this:

import os, errno
try:
os.kill(pid, 0)
except OSError, e:
if e.errno == errno.ESRCH:
# process has finished
...
else:
# process exists
...

Unfortunately, this way cannot save you from getting false
positives with reused pids.

The IMO better way is to use the subprocess module that comes
with Python 2.4. How to replace os.spawn* calls is described
here: http://www.python.org/doc/2.4.2/lib/node244.html

-- 
Lars Gustäbel
[EMAIL PROTECTED]

To a man with a hammer, everything looks like a nail.
(Mark Twain)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs

2007-06-25 Thread Lars Brinkhoff
David Kastrup <[EMAIL PROTECTED]> writes:
> I should think that version 2.3.1 would not even try ftp.  Is that
> on Multics?

Note that the GNU Emacs version jumped directly from 1.12 to 13.
See etc/ONEWS.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Apache cgi and multiple versions of python

2007-08-12 Thread Lars Wessman
I am running OS X and have Python 2.3 installed with the system and
have installed 2.5 using the installer available at pythonmac.org. I
am running the system install of Apache 1.3 and I am not using
mod_python.

When Apache 1.3 runs Python cgi scripts, the cgitb output indicates
that the verision of python being used is 2.3. I would like it to use
Python 2.5. Does anyone have any advice on how to get Apache to use
the version of Python I would like it to?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create TarFile using string buffers

2007-03-19 Thread Lars Gustäbel
On Mon, Mar 19, 2007 at 12:06:39PM -0700, [EMAIL PROTECTED] wrote:
> I have a program that generates a number of files that will be
> packaged into a tarball. Can I stream the content into TarFile without
> first writing them out to the file system? All add(), addfile() and
> gettarinfo() seems to assume there is a file in the disk. But for me I
> seems inefficient to write all the content to the disk and then have
> it read back by the TarFile module.

addfile()'s fileobj argument can be anything that has a read()
method. The amount of bytes to read is taken from the
tarinfo.size attribute. You could let your program write its
data to a StringIO object and pass that object to addfile().

http://docs.python.org/lib/tarfile-objects.html

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Linux is like a wigwam - no Gates, no Windows, Apache inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


Good Book

2007-10-16 Thread Lars Johansen
HI are there any recommended books for an sysadmin who has been mostly
writing shell scripts, but want to move up to create more complex
programs.



-- 
http://mail.python.org/mailman/listinfo/python-list


Any simpler way to do this

2007-12-07 Thread Lars Johansen
I have a function that looks like this:

def Chooser(color):

if color == "RED":
x = term.RED
elif color == "BLUE":
x = term.BLUE
elif color == "GREEN":
x = term.GREEN
elif color == "YELLOW":
x = term.YELLOW
elif color == "CYAN":
x = term.CYAN
elif color == "MAGENTA":
x = term.MAGENTA
return x


Wouldn there been easier if I could just skip all the "*if's" and just
"return term.color", however this gives a syntax error, are there any
clever way to do this ?
-- 
Lars Johansen <[EMAIL PROTECTED]>

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rounding

2007-12-18 Thread Lars Johansen
that does not round up.. int(round(6.345)) maybe
tir, 18.12.2007 kl. 11.53 +0300, skrev Vladimir Rusinov:
> 
> 
> On 12/15/07, katie smith <[EMAIL PROTECTED]> wrote:
> if i have a number 6.345 and i wanted it to be 6 without
> subtracting .345 because it won't always be .345 what do i do?
> 
> how do i round to the nearest whole number. Or in this case
> round down. Is there an easy way to round down to the nearest
> whole number?
> 
> init() ? 
> 
> 
> 
> 
> -- 
> Vladimir Rusinov
> GreenMice Solutions: IT-решения на базе Linux
> http://greenmice.info/ 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Bug writing/reading to file.

2007-12-24 Thread Lars Johansen
text.txt is only read when you open the file, that means that your read
statement, doesnt now of what has been written to the file, since it was
opened..

under if if option == "1":
you should add, then it will be re-read for every read
abc = open('text.txt')
query = abc.readlines()

man, 24.12.2007 kl. 03.53 -0800, skrev [EMAIL PROTECTED]:
> Hi! :)
> 
> Im new to python, and I have made a electronic diary - its just a
> task. Here is the code:
> http://pastebin.com/m49391798
> 
> The bug is (feel free to download and test it) that i can't see what i
> wrote in the diary without restarting the program. Here is an example:
> 
> 1: I start the program
> 2: (text.txt is empty)
> 3: I write "hello, how are you?" with the writing-function in the
> program
> 4; I use the read-all-function in the program.
> 5: There is no entries in the diary. But if I restart the program, I
> can read the file.
> 
> The strange thing is that if i watch the file contents while im using
> the program, I see that i add the line "hello, how are you?" to the
> file, but i can't read it with the read-function.
> 
> Can this be a problem with file-pointers? And how can i solve it?
-- 
Lars Johansen <[EMAIL PROTECTED]>
eZ Systems

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Quick Problem

2006-04-18 Thread Lars Yencken
Hello,

On Tue, 18 Apr 2006 19:05:06 -0700, [EMAIL PROTECTED] wrote:
> Here is my code:
> 
> cw = 0   #Computer wins total
> uw = 0   # User wins total
> 
> def win(who):
> if who == 1:
> cw = cw + 1# computer win
> elif who == 2:
> uw = uw + 1# user win
> 

Try adding into the first line of your win function:

global uw, cw

Then Python knows to look outside your function to find those variables.

Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [HELP] SMTPlib not sending my mail

2008-01-29 Thread Lars Johansen
have you checked your mail server logs ?

tir, 29.01.2008 kl. 00.24 -0800, skrev ashok.raavi:
> Hi,
> 
> I am also facing the same problem, smtplib used to send mail a while
> back but it stopped sending mails.
> 
> when i run this in interpreter
> >>> import smtplib
> >>> s = smtplib.SMTP("localhost")
> >>> s.sendmail(from, to, "message")
> {}
> >>>
> 
> though it is not giving any error, it is not sending mail.
> 
> Any help is appreciated.
> 
> ornto wrote:
> > Hi, I'm trying to create an application which checks a
> > dynamic web site and on certain events sends an email to me.
> > My problem though is with the email task. By now I made this
> >   simple test code:
> >
> > #prova invio email
> > smtpserver = smtplib.SMTP(mailserver)
> > messaggio= "Messaggio di prova"
> > print mail
> > print messaggio
> > smtpresult=smtpserver.sendmail("Watcher",mail,messaggio)
> > if smtpresult:
> >  print smtpresult
> > smtpserver.quit()
> >
> > "mailserver" and "mail" values are loaded from a ini file
> > and they're correct.
> > The call to smtpserver gives back no errors (smtpresult
> > remains empty).
> > The running enviroment gives no error.
> > So, it looks like that the program works alloright, sending
> > the mail- BUT, I receive no mail! I've tried to change the
> > smtp server with another one which still works with my isp,
> > with no luck. If I try a smtp which doesn't give me access,
> > I correctly receive an error from the program.
> > What might be the problem?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Start Python at client side from web app

2009-01-21 Thread Lars Behrens
Thomas Guettler wrote:

> But I don't want to update the installation too often. Here is my idea:
> 
> We create a custom mime-type and register it on the client PC. The web
> application can send signed python code to the client PC. If the signature
> is correct, the code will be executed at the client. The signature
> prevents others from executing code.

My first thought was: Wouldn't it be much easier to start the script via
ssh?

-- 
Cheerz Lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: reading file to list

2009-01-21 Thread Lars Behrens
Rhodri James wrote:

> I *was* thinking of code produced in the real world, and I don't buy
> your assertion.  I'm not an academic, and I wouldn't hesitate to lay
> down a line of code like that.  As I said before, it fits into English
> language idioms naturally, and as a result is pretty self-descriptive.

As a non-native speaker and non-academic, I don't understand the "fittine
into English language idioms naturally" which is mentioned here in the
different subthreads. Could you try to explain that for me?

TIA

-- 
Cheerz Lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: reading file to list

2009-01-21 Thread Lars Behrens
Lars Behrens wrote:

> As a non-native speaker and non-academic, I don't understand the "fittine
   "fitting", I meant. Sorry ^^  

-- 
Cheerz Lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent of py2exe in other os

2008-10-07 Thread Lars Stavholm
Almar Klein wrote:
> Hi,
> I was going to say "try google", but it seems quite hard to find indeed.
> Use "freeze" for linux and "py2app" for osx.

http://python.net/crew/atuining/cx_Freeze
/L

> I know of a program called gui2exe which is a gui which uses the three
> to compile executables of your os of choise (but I think only py2exe was
> implemented thus far).
> 
> Almar
> 
> 2008/10/7 Astan Chee <[EMAIL PROTECTED] >
> 
> Hi,
> I was just wondering if there is a equivalent of py2exe on linux
> (centOS) and mac (OS X). I have a python script that uses wx and I
> dont want to install wx on linux/mac machines. What are my choices?
> Thanks
> Astan
> 
> -- 
> "Formulations of number theory: Complete, Consistent, Non-trivial.
> Choose two." -David Morgan-Mar
> 
> 
> 
> Animal Logic
> http://www.animallogic.com
> 
> Please think of the environment before printing this email.
> 
> This email and any attachments may be confidential and/or
> privileged. If you are not the intended recipient of this email, you
> must not disclose or use the information contained in it. Please
> notify the sender immediately and delete this document if you have
> received it in error. We do not guarantee this email is error or
> virus free.
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


Re: open a shell prompt froma python program

2008-10-30 Thread Lars Stavholm
gaurav kashyap wrote:
> Dear all,
> 
> Can u tell me a python program that when executed in a shell
> prompt,opens another shell prompt.
> 
> Simply i want to open a shell prompt from a python program.

I think you're looking for:

import os
os.system("/bin/sh")

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to process a very large (4Gb) tarfile from python?

2008-07-17 Thread Lars Gustäbel
On Thu, Jul 17, 2008 at 10:39:23AM -0700, Uwe Schmitt wrote:
> On 17 Jul., 17:55, Terry Carroll <[EMAIL PROTECTED]> wrote:
> > On Thu, 17 Jul 2008 06:14:45 -0700 (PDT), Uwe Schmitt
> >
> > <[EMAIL PROTECTED]> wrote:
> > >I had a look at tarfile.py in my current Python 2.5 installations
> > >lib path. The iterator caches TarInfo objects in a list
> > >tf.members . If you only want to iterate and you  are not interested
> > >in more functionallity, you could use "tf.members=[]" inside
> > >your loop. This is a dirty hack !
> >
> > Thanks, Uwe.  That works fine for me.  It now reads through all 2.5
> > million members, in about 30 minutes, never going above a 4M working
> > set.
> 
> Maybe we should post this issue to python-dev mailing list.
> Parsing large tar-files is not uncommon.

This issue is known and was fixed for Python 3.0, see
http://bugs.python.org/issue2058.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Es genügt nicht nur, keine Gedanken zu haben,
man muß auch unfähig sein, sie auszudrücken.
(anonym)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to process a very large (4Gb) tarfile from python?

2008-07-19 Thread Lars Gustäbel
On Thu, Jul 17, 2008 at 11:41:50PM -0700, Uwe Schmitt wrote:
> On 17 Jul., 22:21, Lars Gustäbel <[EMAIL PROTECTED]> wrote:
> >
> > > Maybe we should post this issue to python-dev mailing list.
> > > Parsing large tar-files is not uncommon.
> >
> > This issue is known and was fixed for Python 3.0, 
> > seehttp://bugs.python.org/issue2058.
> 
> The proposed patch does not avoid caching the previous values of the
> iterator, it just reduces the size of each cached object.
> It would be nice to be able to avoid caching on demand, which would
> make iteration independent of the size of the tar file.

The size of the archive doesn't matter, it's the number of members. And I
wouldn't call it caching either. The members are stored in order to have a
table of contents and to allow random access. Also, the members list is
required for resolving hard links within the archive. It cannot be dropped
without side-effects.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Those who would give up essential liberty, to purchase a little
temporary safety, deserve neither liberty nor safety.
(Benjamin Franklin)
--
http://mail.python.org/mailman/listinfo/python-list


python for *nix system admins

2008-09-27 Thread Lars Stavholm
Hi All,

I'm new to this list and hoping that this is not off-topic.
If it is, please point me in the right direction.

I seem to recollect a python module or library for *nix sysadmins,
but I can't for the life of me find it again.

The module (or library) somehow added unix command capabilities
to the python language. It seemed like a lesser known, perhaps new,
python library or module.

Any input or ideas appreciated
/Lars Stavholm
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for *nix system admins

2008-09-27 Thread Lars Stavholm
km wrote:
> import os

Thanks, but I'm aware of the standard libraries like os, sys,
commands, and whatnot. I'm looking for a non-standard library
that acts like a wrapper for the unix commands. I have seen it,
I just can't find it again.
/L

> On Sat, Sep 27, 2008 at 1:35 PM, Lars Stavholm <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> Hi All,
> 
> I'm new to this list and hoping that this is not off-topic.
> If it is, please point me in the right direction.
> 
> I seem to recollect a python module or library for *nix sysadmins,
> but I can't for the life of me find it again.
> 
> The module (or library) somehow added unix command capabilities
> to the python language. It seemed like a lesser known, perhaps new,
> python library or module.
> 
> Any input or ideas appreciated
> /Lars Stavholm
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

--
http://mail.python.org/mailman/listinfo/python-list


Re: python for *nix system admins

2008-09-28 Thread Lars Stavholm
Thank you all for your input.
/Lars

Lars Stavholm wrote:
> Hi All,
> 
> I'm new to this list and hoping that this is not off-topic.
> If it is, please point me in the right direction.
> 
> I seem to recollect a python module or library for *nix sysadmins,
> but I can't for the life of me find it again.
> 
> The module (or library) somehow added unix command capabilities
> to the python language. It seemed like a lesser known, perhaps new,
> python library or module.
> 
> Any input or ideas appreciated
> /Lars Stavholm
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

--
http://mail.python.org/mailman/listinfo/python-list


definition of sub-functions in the hotshot profiler

2006-03-23 Thread Lars Woetmann
what is the definition of sub-functions in the hotshot profiler? and just
as important what is not sub-functions

from the output I can see that functions I made and functions in
/usr/lib/python2.4/textwrap.py is considered sub-functions, but I call a
lot of other functions in the python library and they are not in the
output, so how come textwrap is?


--code

import hotshot, hotshot.stats
prof = hotshot.Profile("openAnswerWindow.prof")
prof.runcall(self.openAnswerWindow)
prof.close()
stats = hotshot.stats.load("openAnswerWindow.prof")
stats.sort_stats('time', 'calls')
stats.print_stats()

--output

 195 function calls in 0.005 CPU seconds

   Ordered by: internal time, call count

ncalls tottime percall  cumtime  percall filename:lineno(function)
 1 0.0010.0010.0050.005 
/home/lars/skole/scriptsprog/rapport/code/m/kw/KeywordWindow.py:399(openAnswerWindow)
18 0.0010.0000.0020.000 m/kw/AnswerWindow.py:22(setText)
 9 0.0010.0000.0010.000 
include/FancyListViewItem.py:7(__init__) 
 1 0.0000.0000.0030.003 m/kw/AnswerWindow.py:53(setQuestionItem)
18 0.0000.0000.0010.000 
/usr/lib/python2.4/textwrap.py:292(wrap) 
18 0.0000.0000.0000.000 /usr/lib/python2.4/textwrap.py:265(wrap)
 9 0.0000.0000.0010.000 m/kw/AnswerWindow.py:11(__init__)
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:94(__init__)
 9 0.0000.0000.0010.000 
/home/lars/skole/scriptsprog/rapport/code/include/IntColumnListViewItem.py:7(__init__)
36 0.0000.0000.0000.000 m/kw/AnswerWindow.py:29(text)
 1 0.0000.0000.0000.000 
/home/lars/skole/scriptsprog/rapport/code/m/kw/QuestionSetModel.py:378(getAllAnswers)
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:131(_split) 
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:114(_munge_whitespace) 
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:192(_wrap_chunks)
 2 0.0000.0000.0000.000 m/kw/AnswerWindow.py:48(setTitle) 
 1 0.0000.0000.0000.000 m/kw/AnswerWindow.py:71(clearAll) 
 0 0.000 0.000  profile:0(profiler)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding contents from string

2010-02-16 Thread Lars Behrens
danin wrote:

> can anyone please tell me about how to do this.

Now come on, you have to give a *bit* more information. What have you done 
so far? What did you plan? What are the rules for finding the string?

-- 
Cheerz Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-24 Thread Lars Gustäbel
On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote:
> I stumbled uppon this and find it somewhat odd: some class methods of
> TarFile and TarInfo do not appears in either the online documentation or
> search while they have a doc string:
> 
> http://docs.python.org/search.html?q=gzopen
> http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile
> 
> See script at the end for list of class methods.
> 
> Is this "by design" or is there some an odd bug in doc generation lurking
> around? This somehow seem to be specific to module tarfile. Fraction
> classmethod from_float() is available in the documentation and found by a
> search for example...

First of all, Python's module documentation is not generated from module
docstrings, each module has its own rst text file in the documentation tree
instead.

But to answer your question: Yes, this is intentional. The TarFile class has
three classmethods taropen(), gzopen(), and bz2open() each for a specific
compression method. These three are used internally by the TarFile.open()
classmethod and are not intended to be called directly. The TarFile.open()
method is the one that is publicly documented and supposed to be used. It
decides which of the three methods to use based on the mode argument and
does many more other high-level things as well.

Regards,

-- 
Lars Gustäbel
l...@gustaebel.de

I do not care to belong to a club that
accepts people like me as members.
(Groucho Marx)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-25 Thread Lars Gustäbel
On Wed, Feb 24, 2010 at 04:29:18PM -0500, Terry Reedy wrote:
> On 2/24/2010 5:14 AM, Lars Gustäbel wrote:
>> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote:
>>> I stumbled uppon this and find it somewhat odd: some class methods of
>>> TarFile and TarInfo do not appears in either the online documentation or
>>> search while they have a doc string:
>>
>> But to answer your question: Yes, this is intentional. The TarFile class has
>> three classmethods taropen(), gzopen(), and bz2open() each for a specific
>> compression method. These three are used internally by the TarFile.open()
>> classmethod and are not intended to be called directly. The TarFile.open()
>> method is the one that is publicly documented and supposed to be used. It
>> decides which of the three methods to use based on the mode argument and
>> does many more other high-level things as well.
>
> By current standards, the three private methods should be prefixed with  
> '_' to indicate their private status. Could they be changed to head off  
> such questions?

I hope that this is not necessary. There are quite a few TarFile methods
more that are not documented and don't start with an underscore. I don't think
renaming all these is a good idea.

The original intention behind these methods was that I wanted a lower level API 
for
TarFile that can be used for subclassing but stays as stable as possible at the
same time. Methods starting with underscores look very much like you can't make
use of them. I don't know if this was a particularly good idea back then and I
don't know how popular it is to subclass the TarFile class to customize it, but
we cannot simply change the methods' names at this point if we don't want to
break other people's code. In other words, the cure sounds worse than the
disease in my opinion.

-- 
Lars Gustäbel
l...@gustaebel.de

I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth.
(Umberto Eco)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-26 Thread Lars Gustäbel
On Fri, Feb 26, 2010 at 09:28:04AM +0100, Baptiste Lepilleur wrote:
> 2010/2/24 Lars Gustäbel 
> 
> > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote:
> > > I stumbled uppon this and find it somewhat odd: some class methods of
> > > TarFile and TarInfo do not appears in either the online documentation or
> > > search while they have a doc string:
> > >
> > But to answer your question: Yes, this is intentional. The TarFile class
> > has three classmethods taropen(), gzopen(), and bz2open() each for a
> > specific compression method. These three are used internally by the
> > TarFile.open() classmethod and are not intended to be called directly. The
> > TarFile.open() method is the one that is publicly documented and supposed
> > to be used. It decides which of the three methods to use based on the mode
> > argument and does many more other high-level things as well.
> >
> 
> I think it would be best to annotate the help string to let people know of
> the facts it is not intended for public usage (or restriction that apply,
> e.g. only for subclassing as you hinted in another post).

Well, then please take the time and open an issue at bugs.python.org, so
that this won't get lost. I will then see what I can do.

-- 
Lars Gustäbel
l...@gustaebel.de

Linux is like a wigwam - no Gates, no Windows, Apache inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


pexpect and logging integration

2010-03-09 Thread Lars Stavholm
Hi all,

has anyone managed to integrate pexpect and logging?

I.e., I'd like to be able to pick up the dialog,
commands sent and responses received, in my logging.
I know about the pexpect logfile, and I can log things
to stdout or stderr, but I really need to log using the
python logging library.

Any thoughts appreciated
/Lars

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pexpect and logging integration

2010-03-11 Thread Lars Stavholm
It works like a charm, thank you!
/Lars

Jean-Michel Pichavant wrote:
> Lars Stavholm wrote:
>> Hi all,
>>
>> has anyone managed to integrate pexpect and logging?
>>
>> I.e., I'd like to be able to pick up the dialog,
>> commands sent and responses received, in my logging.
>> I know about the pexpect logfile, and I can log things
>> to stdout or stderr, but I really need to log using the
>> python logging library.
>>
>> Any thoughts appreciated
>> /Lars
>>
>>   
> I had to implement this.
> It's a bit of a hack, but it does the job.
> 
> The following code is tested with python 2.5, I remember pexpect behaves
> slightly differently in python 2.3.
> 
> import logging
> import pexpect
> import re
> 
> # this will be the method called by the pexpect object to log
> def _write(*args, **kwargs):
>content = args[0]
># let's ignore other params, pexpect only use one arg AFAIK
>if content in [' ', '', '\n', '\r', '\r\n']:
>return # don't log empty lines
>for eol in ['\r\n', '\r', '\n']:
># remove ending EOL, the logger will add it anyway
>content = re.sub('\%s$' % eol, '', content)
>return logger.info(content) # call the logger info method with the
> reworked content
> 
> 
> # our flush method
> def _doNothing():
>pass
> 
> # get the logger
> logger = logging.getLogger('foo')
> 
> # configure the logger
> logger.handlers=[]
> logger.addHandler(logging.StreamHandler())
> logger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s -
> %(name)s - %(levelname)s - %(message)s"))
> logger.setLevel(logging.INFO)
> 
> # give the logger the methods required by pexpect
> logger.write = _write
> logger.flush = _doNothing
> 
> p = pexpect.spawn('echo "hello world !!"', logfile=logger)
> p.expect('!!')
> 
> ... 2010-03-10 15:01:31,234 - foo - INFO - hello world !!
> 
> Hope it helps.
> 
> JM
> 
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tarfile and progress information

2010-07-14 Thread Lars Gustäbel
On Wed, Jul 07, 2010 at 11:23:22AM -0400, Nathan Huesken wrote:
> I am packing large files with tarfile. Is there any way I can get
> progress information while packing?

There is no builtin way in tarfile, but there are several possible solutions:

1. Replace the tarfile.copyfileobj() function that is used to copy the files'
contents to the archive with your own.

2. Subclass the TarFile class, replace the addfile() method, and wrap every
file object argument into an object that triggers a callback function for each
block of data being read:

"""
import sys
import os
import tarfile


class FileProxy(object):

def __init__(self, fobj, callback):
self.fobj = fobj
self.callback = callback
self.size = os.fstat(self.fobj.fileno()).st_size

def read(self, size):
self.callback(self.fobj.tell(), self.size)
return self.fobj.read(size)

def close(self):
self.callback(self.size, self.size)
self.fobj.close()


class MyTarFile(tarfile.TarFile):

def __init__(self, *args, **kwargs):
self.callback = kwargs.pop("callback")
super(MyTarFile, self).__init__(*args, **kwargs)

def addfile(self, tarinfo, fileobj=None):
if self.callback is not None and fileobj is not None:
fileobj = FileProxy(fileobj, self.callback)
super(MyTarFile, self).addfile(tarinfo, fileobj)


def callback(processed, total):
sys.stderr.write("%.1f%% \r" % (processed / float(total) * 100))


tar = MyTarFile.open("test.tar.gz", "w:gz", callback=callback)
tar.add("...")
tar.close()
"""

3. If you have a defined set of files to add you can do something like this:

tar = tarfile.open("test.tar.gz", "w:gz")
for filename in filenames:
tarinfo = tar.gettarinfo(filename)
fobj = FileProxy(open(filename, "rb"), callback)
tar.addfile(tarinfo, fobj)
fobj.close()


I hope this helps.

Regards,

-- 
Lars Gustäbel
l...@gustaebel.de

The power of accurate observation is called cynicism
by those who have not got it.
(George Bernard Shaw)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange python script behaviour

2009-08-04 Thread Lars Behrens
Łukasz wrote:

> The strangest thing is that if I change command in CRON
> 
> from
> python /home/xxx/script.py
> to
> python /home/xxx/script.py  > /tmp/script.log 2>&1
> 
> the script always works correctly!!!
> 
> The question is WHY? Any ideas?

Seems to me that this is more of a shell thing...

First of all, it is always a good idea to call applications with their full
path from cronjobs:

/usr/bin/python /home/xxx/script.py or whatever the output of your "which
python" may be.

How did you create the cronjob? Dependending on the editor you used, maybe
there is a missing newline...

-- 
Cheerz Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Lars Gustäbel
On Mon, Aug 10, 2009 at 08:50:21AM -0400, Esmail wrote:
> I was wondering if it possible to specify a compression level when I
> tar/gzip a file in Python using the tarfile module. I would like to
> specify the highest (9) compression level for gzip.

tarfile uses gzip.GzipFile() internally, GzipFile()'s default compression level
is 9.

> When I create a simple tar and then gzip it 'manually' with compression
> level 9, I get a smaller archive than when I have this code execute with
> the w:gz option.

How much smaller is it? I did a test with a recent Linux kernel source tree
which made an archive of 337MB. Command-line gzip was ahead of Python's
GzipFile() by just 20200 bytes(!) with an archive of about 74MB.

> Is the only way to accomplish the higher rate to create a tar file
> and then use a different module to gzip it (assuming I can specify
> the compression level there)?

If you need the disk space that badly, the alternative would be to pipe
tarfile's output to command-line gzip somehow:

fobj = open("result.tar.gz", "w")
proc = subprocess.Popen(["gzip", "-9"], stdin=subprocess.PIPE, stdout=fobj)
tar = tarfile.open(fileobj=proc.stdin, mode="w|")
tar.add(...)
tar.close()
proc.stdin.close()
fobj.close()

Cheers,

-- 
Lars Gustäbel
l...@gustaebel.de

A physicist is an atom's way of knowing about atoms.
(George Wald)
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >