Thank you dear Gribouillis
I'll try what you suggested and will tell the results soon.
thank you all again.
Thank you dear Gribouillis
I'll try what you suggested and will tell the results soon.
thank you all again.
Thank you pyguy62.
but unfortunately "set()" is not supported by the Python version I must use.
Is there any way to define it manually(i.e. define the set function in this script)?
Hi All
How can I select some random names from a list, so that in next time, those previously selected names become omitted from the list?
for example, say we have 100 names in test.txt file, and we want to select 3 names randomly. then by recalling the selection function, we again select 3 names from remaining 97 names, and so on.
Please Note: I cant use pickle or cpickle, because I'm using python 2.2.2(pys60 1.45) on my phone and it doesnt support pickle.
here is my code, but every time I run it, it again selects from original 100 names.
f = open('e:\\test.txt', 'r')
names = f.readlines()
used = []
def shuffle(x):
i = len(x)
while i > 1:
i = i - 1
j = randrange(i)
x[j], x[i] = x[i], x[j]
return
def randSelect():
shuffle(names)
for i in xrange(3):
x = names[i]
if x not in used:
names.pop(i)
used.append(x)
print x
randSelect()
any help or suggestions is highly appreciated.
maybe something like this:
porttype = "Gi"
print "sh int counters errors | i %s.*/1 " % porttype
>>> sh int counters errors | i Gi.*/1
Thank you guys
in python s60 1.45, python 2.2 and python 2.5.1 it gives error,
anyway thank this great community. I will mark this thread as solved, because my main problem in first post is solved.
I think that the problem is in the site itself.
If I can find out how they encode Farsi strings to codes like this: %D8%A7%DB%8C%D9%84%D8%A7%D9%85
then the problem will solve easily, i think.
this encoding seems like Hexadecimal, but i faild to encode Farsi strings to valid hex codes
the problem is that with this code, it allways saves the Site's default png image( here for Province: Tehran and City: Tehran) no matter which province or city we use in urlopen method.
if we use for example:
url = 'http://www.owghat.com/owghat.png.aspx?Province=کرمان&City=جیرفت'
it again saves the default png for tehran(Province=تهران&City=تهران).
it means that it actually doesnt open the url we use with Farsi city or province names.
thank you dear pyTony.
First problem solved:D
And yes you are right about that string. but the string is Persian(farsi) and i think its utf-8. please tell me if I'm wrong.
but I dont know how they encode urls like this.
in IE the adress is:
http://www.owghat.com/owghat.png.aspx?Province=ایلام&City=مهران
and in FireFox it is:
http://www.owghat.com/owghat.png.aspx?Province=%D8%A7%DB%8C%D9%84%D8%A7%D9%85&City=%D9%85%D9%87%D8%B1%D8%A7%D9%86
I need to download 300 images for 300 cities in 30 provinces and its a damn huge job.
Hi All
When trying to open a URL with bellow code, it Gives "TypeError: not all arguments converted during string formatting"
import urllib
City="%D9%85%D9%87%D8%B1%D8%A7%D9%86"
Province="%D8%A7%DB%8C%D9%84%D8%A7%D9%85"
myurl = 'http://www.owghat.com/owghat.png.aspx?Province='+'%s'+'&City='+'%s'%(Province, City)
#the real address is:http://www.owghat.com/owghat.png.aspx?Province=%D8%A7%DB%8C%D9%84%D8%A7%D9%85&City=%D9%85%D9%87%D8%B1%D8%A7%D9%86
a="e:\\img.png"
urllib.urlretrieve(myurl,a)
So, what I'm doing wrong?
AND Another question: How to encode a utf-8 string(example: مهران) to something like "%D9%85%D9%87%D8%B1%D8%A7%D9%86" in a url?
Thanks in advance for any help.
I think It only accepts Integers and convert them to Unicode strings:
>>> a='%u' % -7
>>> print type(a)
<type 'str'>
Thank you both.
problem solved by tweaking the code u gave to me.
Thanks again for your reply
as I said the code works, without exceptions.
it gets the value of "thing" and encodes it to all encodings at once.
its ok, but, I want the User select which encoding he needs the string to be encoded. sorry if i cant be more clear(because of language barrier, Im not an English speaker).
in other word:
i want to input encoding selectively:
Input 1: the string I want to Encode or decode
Input 2: one or two of the encodings in list "codes"
Output: Printing out the Encoded/Decoded String
@pyTony: I want to doing this in my mobile python(compatible with Python 2.2), and it has not all of the libraries
Sorry for my bad English
Thanks Gribouillis,
Now it works, but it en/decodes the string in all encodings.
I want to select the encoding freely, for example, something like this:
en1 = encoder('String One', 2)# for base64
en2 = encoder('String Two', 3)# for hex
#en3 = ....
#and so on
Hi All
Please some one Help me find out why this code doesn't work:
codes=['zlib', 'zip', 'base64', 'hex', 'utf-8']
def encoder(str, i):
return str.encode(codes[i])
def decoder(str, i):
return str.decode(codes[i])
en = encoder('Some string here', 2)
print en
Is "d" here stands for "digit"?
this bellow code does the same but instead of 0's it prints empty spaces"
print('%0*s' % (3, 7))
what about "s" here? does it mean "string"?
Thanks a lot again Gribouillis for additional info.
Really Thank you Gribouillis for your fast reply.
Yes! zip is what I was in need of Exactly.
I came up with this:
list1=['Item1', 'Item2', 'Item3', 'Item4']
list2=['1','2','3','4']
for i,j in zip(list1, list2):
print '%s______%s'%(j, i)
and the Result:
1______Item1
2______Item2
3______Item3
4______Item4
Just Curious, Can it be done in another way?
Hello All
This is my first post in this forum, despite my long visiting hours as a guest:D
I don't have any background in programming and I'm a newbie in python too. But Learning python for S60(Python distro for Symbian Phones.
anyway, I have a problem with printing from two lists.
what I'm trying to do is printing something like "Item1(from list1):::Item1(from list2)" for each item in both lists:
list1 = [Item1, Item2, Item3,... ItemN]
list2=[Item1, Item2, Item3,... ItemN]
for i in list1:
for j in list2:
print '%s:::%s'%(i,j)
this code doesn't give the result I want.
Python Experts please give me a hint how to do this.
any help or suggestion will be more than appreciated.
thanks in Advance
PS: sorry my bad English