Is this a bug of str.join?

F

fireinice

Hi, all
I'm just working around to generate some fake file for parsing. and I
notice some weired thing happen.
time = str(random.randint(1000000000000000, 9999999999999999))
s_id = str(random.randint(1000000000000000, 9999999999999999))
p_id = str(random.randint(1000000000000000, 9999999999999999))
a_id = str(random.randint(1000000000000000, 9999999999999999))
s = "test"
a = [time, s_id, p_id, a_id, s]
print '\t'.join(a)

the output is:
3107903582321032 6101282916386924 719897196119318 1780339444980186test

you can notice that there is no tab between a_id and s
if I switch a_id and p_id, it still happen, but if I delete one of
ids, the problem gone.
I tried this with python2.6 from debian source and python2.3 which I
compiled from source. the result are both the same.
What happened to str.join?
thanks
 
F

fireinice

Hi, all
I'm just working around to generate some fake file for parsing. and I
notice some weired thing happen.
    time = str(random.randint(1000000000000000, 9999999999999999))
    s_id = str(random.randint(1000000000000000, 9999999999999999))
    p_id = str(random.randint(1000000000000000, 9999999999999999))
    a_id = str(random.randint(1000000000000000, 9999999999999999))
    s = "test"
    a = [time, s_id, p_id, a_id, s]
    print '\t'.join(a)

the output is:
3107903582321032        6101282916386924        719897196119318 1780339444980186test

you can notice that there is no tab between a_id and s
if I switch a_id and p_id, it still happen, but if I delete one of
ids, the problem gone.
I tried this with python2.6 from debian source and python2.3 which I
compiled from source. the result are both the same.
What happened to str.join?
thanks

I'm sorry, I found it should be the terminal width caused visual
problem, please kindly ignore this post.
 
S

Stefan Behnel

fireinice, 16.02.2011 07:24:
Hi, all
I'm just working around to generate some fake file for parsing. and I
notice some weired thing happen.
time = str(random.randint(1000000000000000, 9999999999999999))
s_id = str(random.randint(1000000000000000, 9999999999999999))
p_id = str(random.randint(1000000000000000, 9999999999999999))
a_id = str(random.randint(1000000000000000, 9999999999999999))
s = "test"
a = [time, s_id, p_id, a_id, s]
print '\t'.join(a)

the output is:
3107903582321032 6101282916386924 719897196119318 1780339444980186test

you can notice that there is no tab between a_id and s

Likely just a presentation problem in your terminal. Try with a single
space instead of tabs and see the difference.

Stefan
 
S

Stefan Behnel

fireinice, 16.02.2011 07:32:
Hi, all
I'm just working around to generate some fake file for parsing. and I
notice some weired thing happen.
time = str(random.randint(1000000000000000, 9999999999999999))
s_id = str(random.randint(1000000000000000, 9999999999999999))
p_id = str(random.randint(1000000000000000, 9999999999999999))
a_id = str(random.randint(1000000000000000, 9999999999999999))
s = "test"
a = [time, s_id, p_id, a_id, s]
print '\t'.join(a)

the output is:
3107903582321032 6101282916386924 719897196119318 1780339444980186test

you can notice that there is no tab between a_id and s
if I switch a_id and p_id, it still happen, but if I delete one of
ids, the problem gone.
I tried this with python2.6 from debian source and python2.3 which I
compiled from source. the result are both the same.
What happened to str.join?
thanks

I'm sorry, I found it should be the terminal width caused visual
problem, please kindly ignore this post.

Well, there's always this that's worth remembering:

http://www.catb.org/~esr/faqs/smart-questions.html#id478549

Stefan
 
T

Terry Reedy

Hi, all
I'm just working around to generate some fake file for parsing. and I
notice some weired thing happen.
time = str(random.randint(1000000000000000, 9999999999999999))
s_id = str(random.randint(1000000000000000, 9999999999999999))
p_id = str(random.randint(1000000000000000, 9999999999999999))
a_id = str(random.randint(1000000000000000, 9999999999999999))
s = "test"
a = [time, s_id, p_id, a_id, s]
print '\t'.join(a)

the output is:
3107903582321032 6101282916386924 719897196119318 1780339444980186test

you can notice that there is no tab between a_id and s
if I switch a_id and p_id, it still happen, but if I delete one of
ids, the problem gone.
I tried this with python2.6 from debian source and python2.3 which I
compiled from source. the result are both the same.
What happened to str.join?
thanks

I'm sorry, I found it should be the terminal width caused visual
problem, please kindly ignore this post.

For future reference, the way to get more info about what is really in a
string is to print its repr(), or even its list() version. Len() is also
helpful. On Windows, both the Command Prompt window and IDLE refuse to
expand tabs, so
['a', '\t', 'b', '\t', 'c']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top