Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
hi ^Bert,

I've just thought that you don't like to use text.replace(' ', '\n'), and so I 
came up with another way to get the job done.

So it was part of a "school-test" - uiuitststs ;-)

follow the hint from Peter then, and inside *your* for-loop ask yourself, how 
to inspect the value of c in a loop and what to do *if* the value of c was ' ' .

as mentioned, a string is immuteable, so you cannot change it *inplace* - you 
have to build a new str-object (has a new object-id the starting with an empty 
string say

newtext = ''
and with each loop over your original text you add one character like

newtext = newtext+c

and only if c has a value of ' ', then you add a different value like '\n'

well, now you should try to understand peters for-loop, and then you should try 
to combine what you have learned with the if-statement within the for(-loop) 
block

happy learning the python-language! It's a great one, this I can promise you!
regards
Michael

* Peter Otten <__pete...@web.de> [2019-01-31 11:15]:
> ^Bart wrote:
> 
> >> Why?
> > 
> > It's a school test, now we should use just what we studied, if than,
> > else, sequences, etc.!
> > 
> > ^Bart
> 
> Hint: you can iterate over the characters of a string
> 
> >>> for c in "hello":
> ... print(c)
> ... 
> h
> e
> l
> l
> o
> 
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
hi,

^Bart  ended in a Mail-Delivery...
so I send it ONLY to the python-list

^Bert, a proper way to do what you'd liked to achieve is the following:

>>> text = "The best day of my life!"
>>> newtext = '\n'.join( text.split() )
>>> print(newtext)
The
best
day
of
my
life!
>>>

regards
Michael

* ^Bart  [2019-01-31 10:22]:
> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
> space=\n
> 
> rightText = text-space
> 
> print(rightText)
> 
> I should have an output like this:
> The
> best
> day
> of
> my
> life!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
hi,
Maybe this is a proper way to do what you'd liked to achieve

>>> text = "The best day of my life!"
>>> newtext = '\n'.join( text.split() )
>>> print(newtext)
The
best
day
of
my
life!
>>>

yours
Michael

* ^Bart  [2019-01-31 10:22]:
> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
> space=\n
> 
> rightText = text-space
> 
> print(rightText)
> 
> I should have an output like this:
> The
> best
> day
> of
> my
> life!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
maybe this is an alternative way to get your wished result.

>>> text = "The best day of my life!"
>>> newtext = '\n'.join( text.split() )
>>> print(newtext)
The
best
day
of
my
life!
>>>

yours
Michael
* ^Bart  [2019-01-31 10:22]:
> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
> space=\n
> 
> rightText = text-space
> 
> print(rightText)
> 
> I should have an output like this:
> The
> best
> day
> of
> my
> life!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't find way to install psycopg2 in 3.5

2015-12-14 Thread Michael Poeltl
hi,

I'm used to compile postgresql from source
(last time it was postgresql-9.4.4 with
./configure --prefix=/usr --enable-thread-safety 
--docdir=/usr/share/doc/postgresql-9.4.4 --with-tcl --with-openssl 
--enable-nls=de --with-libxml
on my linuxmint17-box)

and then the installation of psycopg2 (in my case psycopg2-2.6.1) works just 
fine and smoothly (even for python-3.5!).

If you've got postgresql through a pre-compiled package it is (maybe) necessary 
to *show* where to find 'pg_config' by editing the setup.cfg-file in the 
psycopg2-source-folder.

Have you visited this site?
http://initd.org/psycopg/

regards
Michael

* Dhaval Parekh - NCrypted <dhaval.par...@ncrypted.com> [2015-12-14 09:29]:
> Hello,
> 
>  
> 
> I'm newbie in using python. I've installed python 3.5 and django 1.9 to
> develop web application. I wanted to set postgresql as a DBMS but I couldn't
> complete the setup as it was continuously throwing me an error that psycopg2
> module not found. I've digged a lot but I couldn't find psycopg2 for python
> 3.5. Is it something 3.5 has different scenario for django? I couldn't find
> anyway to complete my setup so I'm going to downgrade to 3.4 as I found
> psycopg2 for 3.4 only. 
> 
>  
> 
> If you have any idea about it then please let me know.
> 
>  
> 
>  
> 
>  
> 
> Regards,
> 
> Dhaval Parekh
> 
> Project Coordinator,
> 
> NCrypted Technologies Pvt. Ltd.
>  <http://www.ncrypted.com/> http://www.ncrypted.com
> 
>  
> 
> An ISO 9001:2008 Certified Company | BID International Quality Crown (2012)
> <http://www.ncrypted.com/iqc-international-quality-crown-award> Award Winner
> 
> IDC: 2nd floor, Shivalik 5, Gondal Road, Rajkot (Gujarat), India | +91 (281)
> 237 8880, 391 8880
> 
> Disclaimer & Privilege Notice: This e-Mail may contain proprietary,
> privileged and confidential information and is sent for the intended
> recipient(s) only. If, by an addressing or transmission error, this mail has
> been misdirected to you, you are requested to notify us immediately by
> return email message and delete this mail and its attachments. You are also
> hereby notified that any use, any form of reproduction, dissemination,
> copying, disclosure, modification, distribution and/or publication of this
> e-mail message, contents or its attachment(s) other than by its intended
> recipient(s) is strictly prohibited. Any opinions expressed in this email
> are those of the individual and may not necessarily represent those of
> NCrypted Technologies Pvt. Ltd. Before opening attachment(s), please scan
> for viruses.
> 
> NCrypted is a registered trademark of NCrypted Technologies Pvt. Ltd. in
> India and other countries.
> 
>  
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl <michael.poe...@univie.ac.at>
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.4.3, on linux mint 17 (qiana)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bug in floating point multiplication

2015-07-02 Thread Michael Poeltl
hi Steven,

I'm running python-3.4.2 on a linuxmint16 box and CANNOT reproduce
it is just that
int(i*x) == i
is never True!

hope that helps
regards
Michael

* Steven D'Aprano st...@pearwood.info [2015-07-02 16:56]:
 Despite the title, this is not one of the usual Why can't Python do
 maths? bug reports.
 
 Can anyone reproduce this behaviour? If so, please reply with the version of
 Python and your operating system. Printing sys.version will probably do.
 
 
 x = 1 - 1/2**53
 assert x == 0.
 for i in range(1, 100):
 if int(i*x) == i:
 print(i); break
 
 
 Using Jython and IronPython, the loop runs to completion. That is the
 correct behaviour, or so I am lead to believe. Using Python 2.6, 2.7 and
 3.3 on Centos and Debian, it prints 2049 and breaks. That should not
 happen. If you can reproduce that (for any value of i, not necessarily
 2049), please reply.
 
 See also http://bugs.python.org/issue24546 for more details.
 
 
 
 -- 
 Steven
 
 -- 
 https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl michael.poe...@univie.ac.at
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.3,
  with python-3.4.2, on linux mint 16 (petra)   :-)
  fon: +43-1-4277-51409

  Lehrend lernen wir!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine

2013-05-24 Thread Michael Poeltl
* DRJ Reddy rama29...@gmail.com [2013-05-25 05:26]:
 Planning to start a python online chronicle.What you want to see in it. :)
- idiomatic python (common mistakes; do it 'pythonically')
- interviews
- challenge of the week (how would you solve that?)
- python for kids
- scientific python news
- new python-books

- 


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

-- 
  Michael Poeltl michael.poe...@univie.ac.at
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.3,
  with python-3.2.3, on slackware-13.37   :-)
  fon: +43-1-4277-51409
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python trademark - A request for civility

2013-02-16 Thread Michael Poeltl
hi,

there are also

ruby.co.uk
lua.co.uk

in my opinion someone who is on the ruby-/lua-malinglist too should warn these 
guys

* Steven D'Aprano steve+comp.lang.pyt...@pearwood.info [2013-02-16 06:50]:
 Folks,
 
 It seems that people have been sending threats and abuse to the company
 claiming a trademark on the name Python. And somebody, somewhere, may
 have launched a DDOS attack on their website.
 
 The Python Software Foundation has asked the community for restraint and
 civility during this dispute. Abuse and threats just bring the Python
 community into disrepute.

yeah - that's also my opinion!

Michael
 
 http://pyfound.blogspot.com/2013/02/asking-for-civility-during-our.html
 
 
 
 -- 
 Steven
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Further evidence that Python may be the best language forever

2013-01-29 Thread Michael Poeltl
hi Stefan,

* Stefan Behnel stefan...@behnel.de [2013-01-29 08:00]:
 Michael Torrie, 29.01.2013 02:15:
  On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote:
  My company recently hosted a programming competition for schools
  across the country.  One team made it to the finals using the Python
  client, one of the four default clients provided (I wrote it).  Most
  of the other teams were using Java or C#.  Guess which team won?
 
  http://www.windward.net/codewar/2013_01/finals.html
 
 We did a similar (although way smaller) contest once at a university. The
 task was to write a network simulator. We had a C team, a Java team and a
 Python team, four people each. The Java and C people knew their language,
 the Python team just started learning it.
 
 The C team ended up getting totally lost and failed. The Java team got most
 things working ok and passed. The Python team got everything working, but
 additionally implemented a web interface for the simulator that monitored
 and visualised its current state. They said it helped them with debugging.
quite interesting!
I'd liked to see the code
is it available for 'download'?

thx
Michael
 
 
  What language was the web page hosted in?  It comes up completely blank
  for me. :)
 
 Yep, same here. Hidden behind a flash wall, it seems.
 
 Stefan
 
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGreSQL 4.1 released

2013-01-05 Thread Michael Poeltl
no python3 support yet?
can you tell us when pygresql will be ready for python3?

thx
Michael


* D'Arcy J.M. Cain da...@pygresql.org [2013-01-03 15:05]:
 ---
 Release of PyGreSQL version 4.1
 ---
 
 It has been a long time coming but PyGreSQL v4.1 has been released.
 
 It is available at: http://pygresql.org/files/PyGreSQL-4.1.tgz.
 
 If you are running NetBSD, look in the packages directory under
 databases. There is also a package in the FreeBSD ports collection
 which will probably be updated shortly.
 
 Please refer to `changelog.txt changelog.html`_
 for things that have changed in this version.
 
 Please refer to `readme.txt readme.html`_
 for general information.
 
 This version has been built and unit tested on:
  - NetBSD
  - FreeBSD
  - openSUSE 12.2
  - Windows 7 with both MinGW and Visual Studio
  - PostgreSQL 8.4, 9.0 and 9.2 32 and 64bit
  - Python 2.5, 2.6 and 2.7 32 and 64bit
 
 -- 
 D'Arcy J.M. Cain
 PyGreSQL Development Group
 http://www.PyGreSQL.org IM:da...@vex.net
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Books?

2012-08-22 Thread Michael Poeltl
I would recommend Dive into Python3

just goole-search
dive into python3 filetype:pdf

and you got it!

regards
Michael

* Anonymous Group anonymous42311...@gmail.com [2012-08-22 03:40]:
 What books do you recomend for learning python? Preferably free and/or
 online.
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: find out whether a module exists (without importing it)

2012-08-07 Thread Michael Poeltl
in my opinion, without importing it makes it unnecessarily complicated.
You just want to know it module xyz exists, or better said can be found
(sys.path).

why not try - except[ - else ]

try:
import mymodule
except ImportError:
#  NOW YOU KNOW it does not exist
#+ and you may react properly
??
* Gelonida N gelon...@gmail.com [2012-08-06 22:49]:
 Is this possible.
 
 let's say I'd like to know whether I could import the module
 'mypackage.mymodule', meaning,
 whther this module is located somewhere in sys.path
 
 i tried to use
 
 imp.find_module(), but
 it didn't find any module name containing a '.'
 
 Am I doing anything wrong?
 
 Is there another existing implementation, that helps.
 
 I could do this manually, but this is something I'd just like to do
 if necessary.
 
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Book for a C Programmer?

2012-05-24 Thread Michael Poeltl
hi,

take
'Pro Python' (by Marty Alchin)

regards
Michael

* hsa...@gmail.com hsa...@gmail.com [2012-05-24 07:54]:
 I am trying to join an online class that uses python. I need to brush up on 
 the language quickly. Is there a good book or resource that covers it well 
 but does not have to explain what an if..then..else statement is?
 
 Thanks.
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python segfault

2012-03-28 Thread Michael Poeltl
hi,

* Dave Angel d...@davea.name [2012-03-28 04:38]:
 On 03/27/2012 06:27 PM, Michael Poeltl wrote:
 hi,
 
 can anybody tell why this 'little stupid *thing* of code' let's 
 python-3.2.2, 2.6.X or python 2.7.2 segfault?
 
 def get_steps2(pos=0, steps=0):
 ... if steps == 0:
 ... pos = random.randint(-1,1)
 ... if pos == 0:
 ... return steps
 ... steps += 2
 ... pos += random.randint(-1,1)
 ... return get_steps2(pos,steps)
 ...
 SNIP
 0
 2
 8
 0
 Segmentation fault
 ?
 
 funny, isn't it?
 I was able to reproduce this segfault on various machines (32bit 64bit), 
 ubuntu, slackware, debian
 python.X segfaults on all of them
 
 thx
 Michael
 
 Others have explained why you can't just raise the recursion limit
 to arbitrarily large values, and why there's no particular bound on
 the possible recursion size.  But the real question is why you don't
 do the completely trivial conversion to a non-recursive equivalent.
 
 All you need do is add a while True:  to the beginning of the
 function, and remove the return statement.
yeah - of course 'while True' was the first, most obvious best way... ;-)
but I was asked if there was a way without 'while True'
and so I started the 'recursive function'

and quick quick; RuntimeError-Exception - not thinking much - just adding
two zeros to the default limit (quick and dirty) - segfault == subject: 
python segfault ;-)

and that was my first time that I received a segfault and not an Exception

NOW it's quite clear ;-)

thank you!
Michael
 
 
 
 -- 
 
 DaveA
 

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


python segfault

2012-03-27 Thread Michael Poeltl
hi,

can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 
2.6.X or python 2.7.2 segfault?

 def get_steps2(pos=0, steps=0):
... if steps == 0:
... pos = random.randint(-1,1)
... if pos == 0:
... return steps
... steps += 2
... pos += random.randint(-1,1)
... return get_steps2(pos,steps)
...
 import random, sys
 sys.setrecursionlimit(10)
 for i in range(200):
... print ( get_steps2() )
...
4
0
8
0
0
0
2
2
166
2
0
0
16
4
2
16
0
0
10
70
152
50
58
0
6
0
0
0
2
8
0
Segmentation fault
?

funny, isn't it?
I was able to reproduce this segfault on various machines (32bit 64bit), 
ubuntu, slackware, debian
python.X segfaults on all of them

thx
Michael
-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random number

2012-03-26 Thread Michael Poeltl
* Nikhil Verma varma.nikhi...@gmail.com [2012-03-26 08:09]:
 Hi All
 
 How can we generate a 6 digit random number from a given number ?
what about this?

 given_number=123456
 def rand_given_number(x):
... s = list(str(x))
... random.shuffle(s)
... return int(''.join(s))
... 
 print (rand_given_number(given_number))
653421
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random number

2012-03-26 Thread Michael Poeltl
* Nikhil Verma varma.nikhi...@gmail.com [2012-03-26 08:49]:
 Hi
 
 I want something to achieve like this :-
 
 def random_number(id): # I am passing it from request
 # do something
 return random_number
 
 Output
 
 random_number(5)
 AXR670
 
 One input that is a number in return you are getting 6 digit alphanumeric
 string.
 
 I tried this
 s = '%06d' % random.randint(0, 99)
 
 it gives : '192862' (a string )
 
 Thanks in advance.
ah - so I misunderstood - I thought you want a permutation of a given
6-digit number

It's still not quite clear to me what role 'id' is playing ... so let's
check this one;
and Steven, who is maybe more experienced than I am will help us ufrther

 import random, string
 def random_number(id):
... characters = list(string.ascii_lowercase +
...   string.ascii_uppercase +
...   string.digits)
... coll_rand = []
... for i in range(6):
... random.shuffle(characters)
... coll_rand.append(characters[0])
... return ''.join(coll_rand)
... 
 id = 5
 print (random_number(id))
puMHCr


regards
Michael


 
 On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl 
 michael.poe...@univie.ac.at wrote:
 
  * Nikhil Verma varma.nikhi...@gmail.com [2012-03-26 08:09]:
   Hi All
  
   How can we generate a 6 digit random number from a given number ?
  what about this?
 
   given_number=123456
   def rand_given_number(x):
  ... s = list(str(x))
  ... random.shuffle(s)
  ... return int(''.join(s))
  ...
   print (rand_given_number(given_number))
  653421
 
 
 
 
 -- 
 Regards
 Nikhil Verma
 +91-958-273-3156


-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking under Python's hood: Will we find a high performance or clunky engine?

2012-01-22 Thread Michael Poeltl
* Ian Kelly ian.g.ke...@gmail.com [2012-01-22 19:29]:
 On Sun, Jan 22, 2012 at 8:50 AM, Rick Johnson
 rantingrickjohn...@gmail.comwrote:
 
 
  What does Python do when presented with this code?
 
  py [line.strip('\n') for line in f.readlines()]
 
  If Python reads all the file lines first and THEN iterates AGAIN to do
  the strip; we are driving a Fred flintstone mobile. If however Python
  strips each line of the lines passed into readlines in one fell swoop,
  we made the correct choice.
 
  Which is it Pythonistas? Which is it?
I cannot understand why it is so important for you to store
lines out of a textfile in a list without '\n'. 
have you ever considered the *pros* of leaving '\n' ?
 
 
 Two iterations.  And since that is the only possible way to do this, you
 are correct, the language is terribly archaic.  I suggest you switch to
 Ruby ASAP.
why there is only one possibility to do so? in a second i found this
''.join(open('test').readlines()).split('\n')

and if you don't like python, then stick to ruby. who cares???



-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
---
On Sun, Jan 22, 2012 at 8:50 AM, Rick Johnson rantingrickjohn...@gmail.com wrote:


What does Python do when presented with this code?

py [line.strip(\n) for line in f.readlines()]

If Python reads all the file lines first and THEN iterates AGAIN to do
the strip; we are driving a Fred flintstone mobile. If however Python
strips each line of the lines passed into readlines in one fell swoop,
we made the correct choice.

Which is it Pythonistas? Which is it?Two iterations.  And since that is the only possible way to do this, you are correct, the language is terribly archaic.  I suggest you switch to Ruby ASAP.


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


Re: Commands for changing ownership of a file

2011-08-14 Thread Michael Poeltl
in python-3.2.1 I'm using os.system() again, from time to time
maybe that's the one you were looking for?

 os.system('chown user:group /tmp/f')
0
 os.system('ls -l /tmp/f')
-rw-r--r-- 1 user group 0 Aug 15 03:52 /tmp/f

and besides os.chown() (where you ned the uid and gid), you could also use 
subprocess.call() or subprocess.Popen()

regards
Michael
* Jason Hsu jhsu802...@gmail.com [2011-08-15 01:15]:
 I have a script that I execute as root, but I need to change the
 ownership of the files created in the script to that of my username.
 In GNU Bash, the command is something like chown myusername:users.
 What's the equivalent Python command?  I know that there is a command
 that uses numbers for the username and group, but is there a command
 that would allow me to use myusername and users instead of numbers?
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 

slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12

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


Re: how to solve it?

2011-08-01 Thread Michael Poeltl
* 守株待兔 1248283...@qq.com [2011-08-01 06:22]:
 from matplotlib.matlab import *
 Traceback (most recent call last):
   File stdin, line 1, in module
 ImportError: No module named matlab

does this work?
 import matplotlib

next check 'gallery' at
http://matplotlib.sourceforge.net/index.html

choose the graph (click it) you need, and there you can browse the
source-code (python-code)

this is maybe the best starting-point, I guess.

cheers
Michael
-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 

slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12

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


Re: how to solve it?

2011-08-01 Thread Michael Poeltl
* 守株待兔 1248283...@qq.com [2011-08-01 06:22]:
 from matplotlib.matlab import *
 Traceback (most recent call last):
   File stdin, line 1, in module
 ImportError: No module named matlab

is this what you were looking for?
 from matplotlib.pylab import *

cheers
Michael
-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 

slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12

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


Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Michael Poeltl
* Michael Torrie torr...@gmail.com [2011-07-31 03:44]:
 On Jul 29, 2011 6:33 PM, Michael Poeltl michael.poe...@univie.ac.at
 wrote:
 
  what about this?
   ' '.join('/home//h1122/bin///ghi/'.split('/')).split()
  ['home', 'h1122', 'bin', 'ghi']
  
 
 Doesn't work on filenames with spaces in them.
you are right; me, I never put spaces into my filenames and so I didn't
think of this possibility.

so there is another idea, which will not work on dirnames 'with spacs in
them' ;-)
 p = '/path//to///file/i am a file'
 ' 
 '.join(os.path.split(p)[0].split('/')).split().__add__([os.path.split(p)[1]])
['path', 'to', 'file', 'i am a file']

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
-
slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12

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


Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Michael Poeltl
* Alexander Kapps alex.ka...@web.de [2011-07-29 22:30]:
 On 29.07.2011 21:30, Carl Banks wrote:

 It's not even fullproof on Unix.

 '/home//h1122/bin///ghi/'.split('/')

 ['','home','','bin','','','ghi','']
what about this?
 ' '.join('/home//h1122/bin///ghi/'.split('/')).split()  
['home', 'h1122', 'bin', 'ghi'] 
 
;-) 
regards 
Michael

 Carl Banks

 This would also be fixed with normpath() as Dennis Lee Bieber suggested. 
 And my solution with list comprehensions handles this too.

 Still, there might be other path oddities which would break here. I  
 think, that something like a split_all() function should be available in 
 the stdlib, no?

 Actually, it isn't the first time, where I wonder why os.path.split() 
 doesn't do this already. I mean, str.split() doesn't only split on the 
 first part, right?
 -- 
 http://mail.python.org/mailman/listinfo/python-list


-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: os.path needs immediate attention!

2011-07-29 Thread Michael Poeltl
join 'Python-Dev'-mailinglist and tell them!
from now on I will just ignore threads you initiated

does trolling really make that much fun?
* rantingrick rantingr...@gmail.com [2011-07-29 19:25]:
 
 --
  Overview of Problems:
 --
 
  * Too many methods exported.
  * Poor choice of method names.
  * Non public classes/methods exported!
  * Duplicated functionality.
 
 --
  Proposed new functionality:
 --
 
  * New path module will ONLY support one path sep! There is NO reason
 to support more than one. When we support more than one path sep we
 help to propagate multiplicity.We should only support the slash and
 NOT the backslash across ALL OS's since the slash is more widely
 accepted. If an OS does not have the capability to support only the
 slash then that OS is not worthy of a Python builtin module. The users
 of such OS will be responsible for managing their OWN os_legacy.path
 module. We are moving forward. Those who wish to wallow in the past
 will be left behind.
 
  * Introduce a new method named partition which (along with string
 splitting methods) will replace the six methods basename, dirname,
 split, splitdrive, splitunc, splittext. The method will return
 a tuple of the path split into four parts: (drive, path, filename,
 extension). This is the ONLY splitting method this module needs. All
 other splits can use string methods.
 
 --
  Expose of the Warts of current module:
 --
 
 
 ~
  1. Too many methods
 ~
 
 Follows is a list of what to keep and what to cull:
 
  + abspath
  + altsep
  - basename -- path.partition[-2]
  + commonprefix
  + curdir
  + defpath
  + devnull
  - dirname -- os.path.join(drive,path)
  + exists
  + expanduser
  + expandvars
  + extsep
  - genericpath -- should be private!
  + getatime
  + getctime
  + getmtime
  + getsize
  + isabs
  + isdir
  + isfile
  + islink
  + ismount
  + join
  - lexists -- duplicate!
  - normcase -- path = path.lower()
  - normpath -- should not need this!
  - os -- should be private!
  + pardir
  + pathsep
  + realpath
  + relpath
  + sep
  - split -- path.rsplit('/', 1)
  - splitdrive -- path.split(':', 1)
  - splitext -- path.rsplit('.')
  - splitunc -- Unix specific!
  - stat -- should be private!
  + supports_unicode_filenames -- windows specific!
  - sys -- should be private!
  + walk
  - warnings -- should be private!
 
 
 ~
  2. Poor Name Choices:
 ~
 
  * basename -- should be: filename
  * split -- split what?
  * splitext -- Wow, informative!
 
 ~
  3. Non Public Names Exposed!
 ~
 
  * genericpath
  * os
  * stat
  * sys
  * warnings
 
 
 Note: i did not check the Unix version of os.path for this.
 
 ~
  4. Duplicated functionality.
 ~
 
  os.path.lexists.__doc__
 'Test whether a path exists.  Returns False for broken symbolic links'
  os.path.exists.__doc__
 'Test whether a path exists.  Returns False for broken symbolic links'
 
 Should have been one method:
  os.path.exists(path, ignoreSymLnks=False)
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie in python

2008-02-21 Thread Michael Poeltl
A big help for 'easily learning python was and is

Learning Python
(a book written by Mark Lutz)

after having studied this book you are able to think in python

another book I like very much is

Core Python Programming
(written by Wesley Chun)

regards
michael

On Thursday 21 February 2008 03:26:17 pm subeen wrote:
 Dive into Python is a very good book but it's for people who have
 experience in other languages. I liked the book.
 Whatever book you read, please take a look at the Python Tutorial:
 http://docs.python.org/tut/tut.html, it will help.

 regards,
 Subeen.
 http://love-python.blogspot.com/

 On Feb 21, 6:01 pm, 7stud [EMAIL PROTECTED] wrote:
  [EMAIL PROTECTED] wrote:
   Hi anyone
  
   I'm very interesed to learn python and really willing to do so,but
   unfortunately dont know where to start, or what programs need to
   install to start.
  
   Can someone help me to get in the right track, and get a good move?
  
   Thanks for all help
 
  If you're a good student or you have prior programming experience, get
  the book 'Learning Python', which just came out with a 3rd edition, so
  it is the most up to date book.
 
  If you are not such a good student or have no prior programming
  experience, and you want a gentler introduction to python, check out
  the book 'Python Programming for the Absolute Beginner(2nd Ed.)'


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


Re: may be a bug in string.rstrip

2007-11-22 Thread michael poeltl
hi,

what about this


 'exe.torrent'.split('.')[0]
'exe'
 'exe.torrent'.rstrip('toren').rstrip('.')
'exe'


that's what you need, isn't it?

On Friday 23 November 2007 05:09:50 am kyo guan wrote:
 Hi :

   Please look at this code:
  'exe.torrent'.rstrip('.torrent')

 'ex'  -  it should be 'exe', why?

 but this is a right answer:
  '120.exe'.rstrip('.exe')

 '120' -- this is a right value.

   there is a bug in the rstrip, lstrip there isn't this problem.



 Kyo.


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


Re: What is python?????

2007-11-17 Thread michael poeltl
On Saturday 17 November 2007 01:32:52 pm Cope wrote:
 On Nov 17, 5:00 pm, Amit Khemka [EMAIL PROTECTED] wrote:
  On 11/17/07, Cope [EMAIL PROTECTED] wrote:
   In our place we eat pythons for curry. Its delicious.
   And how about your python?
  
   Cope
 
  Not much of the difference here, it is just a bit more flexible. My
  python goes and brings me whatever I wish to eat.
 
  Cheers,
  --
  --
  Amit Khemka

 You must be Python Charmer

just clients of a certain cheese-shop ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list