Re: [Python-ideas] Inconsistencies

2016-09-12 Thread not1xor1

Il 12/09/2016 04:26, Chris Angelico ha scritto:

So whoever created the Universe also created the Creator...

No, God isn't part of the universe, any more than an author is part of
his novel.


your logic is based on the assumption that the _existance_ itself, 
i.e. the mere presence of something, can be explained only by the 
presence of a "creator"


but such agent must  _exists_ to be able to perform 
any act of creation, so, according to the given logic, she-he-it 
(-self) must have been created by some other kind of agent


so there are 0x10 chances:
- 0x00 an infinitive hierarchy of "creators"
   (you might get a stack overflow)
- 0x01 the universe has always been there an the need of an "agent"
   is just due to the classical "every event is explained by
   a purposeful agent" cognitive fallacy

I do not know if the 0x00 item is the right one, but I'm sure that a 
possible 'creator' (just one hierarchical level over our present 
universe) would likely be quite different from all the various ones 
mankind imagined in the course of millennia and would strongly 
disapprove all the psychological projections about her-his-its will 
and the evil done in her-his-its name :-)


p.s. I apologize for my poor English
--
bye
!(!1|1)
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert 'รถ' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread not1xor1

Il 18/09/2016 08:45, Steven D'Aprano ha scritto:

integral part of the letter, like the horizonal stroke in English t or the
vertical bar in English p and b, and in some languages they are modifiers,


well... that is the Latin alphabet

English has no T, P or B (or any other character) but is just 
(mis)using the Latin alphabet (which is just a few centuries older 
than the English language itself) :-)


--
bye
!(!1|1)
--
https://mail.python.org/mailman/listinfo/python-list


Re: alphanumeric list

2011-03-16 Thread not1xor1 (Alessandro)

Il 15/03/2011 09:10, yqyq22 ha scritto:


I would like to put an alphanumeric string like this one
EE472A86441AF2E629DE360 in a list, then iterate inside the entire
string lenght and change each digit with a random digit.
Do u have some suggestion? thanks a lot


hi

I'm not an experienced python programmer but the following code should 
work:


# you need to import the random module to get random numbers
import random

# convert the string in a list (as string are read-only)
l = list('EE472A86441AF2E629DE360')
# initialize the random generator
random.seed()
# index
i = 0
# loop through the characters in the list
for c in l:
# if the current character is a digit
if c.isdigit():
# get a random integer in the 0-9 range
# convert it to a string and replace the old value
l[i] = str(random.randint(0,9))
# increment the list index
i +=1
# convert the modified list back to string and display it
print(''.join(l))

--
bye
!(!1|1)
--
http://mail.python.org/mailman/listinfo/python-list


subclassing str

2010-11-06 Thread not1xor1 (Alessandro)

Hi,

I'd like to know what is the best way to subclass str
I need to add some new methods and that each method (both new and str 
ones) return my new type


For instance I've seen I can do:


class mystr(str):

   def between(self, start, end):
  i = self.index(start) + len(start)
  j = self.index(end, i) + len(end)
  return self[i:j], self[j:]

   def replace(self, old, new='', count=-1):
  return mystr(str.replace(self, old, new, count))

if __name__ == '__main__':

   s = mystr('one two  four')
   print s
   print type(s)
   b,r = s.between('<', '>')
   print b
   print r
   print type(b)
   print type(r)
   c = s.replace('three', 'five')
   print c
   print type(c)


when I ran it I get:

one two  four

three>
 four


one two  four



I guess that if I had redefined the slice method even 'between' would 
have returned 


I wonder if I have to redefine all methods one by one or if there is a 
sort of hook to intercept all methods calls and just change the return 
type


thanks

--
bye
!(!1|1)
--
http://mail.python.org/mailman/listinfo/python-list


Re: subclassing str

2010-11-07 Thread not1xor1 (Alessandro)

Il 07/11/2010 07:41, Chris Rebert wrote:


You could subclass UserString instead of str; all of UserString's
methods seem to ensure that instances of the subclass rather than just
plain strs or UserStrings are returned. See
http://docs.python.org/library/userdict.html#UserString.UserString


I'll have a look at it, thanks


But you should also consider whether your additions absolutely *must*
be methods. Merely instead defining some functions that take strings
as parameters is obviously a simpler, and probably more performant,
approach.


I regularly save web pages (mostly scientific research abstracts) from 
various web sites and use a python script to strip them of ads and 
unneeded informations, embedding the images directly in the html file 
(as base64 encoded data) and at times joining multiple pages into just one


since those sites often change the format of their files I've to 
modify my script accordingly


I'm already using plain functions, but thought that wrapping most of 
them in a str subclass would let me save some time and yield cleaner 
and more manageable code



If you insist on subclassing str, there's no such hook; you'll have to
override all the methods yourself.*


I'll try this route too (at least for the methods I need)
thanks for your help
--
bye
!(!1|1)
--
http://mail.python.org/mailman/listinfo/python-list


Re: subclassing str

2010-11-10 Thread not1xor1 (Alessandro)

Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto:


How exactly does

a.f(b, c)

save time over

 f(a, b, c)


unfortunately in real world you have:

objId = objId.method(args)

vs.

objId = moduleName.method(objId, args)

I know you can use "from moduleName import *", but IMHO that produces 
code much harder to manage and extend

--
bye
!(!1|1)
--
http://mail.python.org/mailman/listinfo/python-list