How to cat None

L

LittlePython

I found out the hard way that I can not cat None. I get an error. Is there a
simple way to cat None without doing some kind of equation ( if this then
that). Is there a isNone() somewhere. I am not too sure I know what None
really means.

I include an example to show what I am talking about in case I am alittle
confused.




from easygui import *
import string

msgbox('Starting Program')

thisfile = fileopenbox(msg='Choose the correct File', title='Matrix Input
File')
input = file(thisfile,'r')

header = string.split(string.strip(input.readline()),',')
header.extend(['55FirstName',
'55Intial','55LastName','55Alias',])

all = input.readlines()
input.close
input = None
matrix = {}
for user in all:
user1 = string.split(string.strip(user),',')
user1.extend(['None']*4) <-------------------------I would like to
None or better NULL this instead of string it
user1 = dict(zip(header,user1))
matrix[user1['OldNTLogon']] = user1

mychoice = choicebox(choices=matrix.keys())
user1 = matrix[mychoice]

alltogether = ''

for KeyName in user1.keys():
if alltogether == '':
alltogether = KeyName + '=' + ' ' + user1.get(KeyName) + '\n'
else:
alltogether = alltogether + KeyName + '=' + user1.get(KeyName) +
'\n' <------- error 'can not cat None with a str' or something like that

msgbox(alltogether,'User Matrix for '+ mychoice )

msgbox('The End')
 
J

Jonathan Gardner

You can just surround the offending value with str(...). You should
probably be doing that anyway, because the value might be a number or
something else not stringish.
 
R

rtilley

LittlePython wrote:
I am not too sure I know what None really means.

It means null, void or lack of value. It is not an empty string. You
can't add None to stings.
<type 'NoneType'>
 
B

bonono

Seems that what you want to do is to create a string in the form of :

"55Init=Init\n55First=first\n55Last=Last\n55Alias=None"

for each dictionary. If that is the case, may be you can try this :

"\n".join("%s=%s" % x for x in user1.iteritems())

Note that you cannot control the ordering of the keys when iterating a
dict which may or may not be a concern for you.
 
L

LittlePython

Thx , I will give this a try.

Seems that what you want to do is to create a string in the form of :

"55Init=Init\n55First=first\n55Last=Last\n55Alias=None"

for each dictionary. If that is the case, may be you can try this :

"\n".join("%s=%s" % x for x in user1.iteritems())

Note that you cannot control the ordering of the keys when iterating a
dict which may or may not be a concern for you.
I found out the hard way that I can not cat None. I get an error. Is there a
simple way to cat None without doing some kind of equation ( if this then
that). Is there a isNone() somewhere. I am not too sure I know what None
really means.

I include an example to show what I am talking about in case I am alittle
confused.




from easygui import *
import string

msgbox('Starting Program')

thisfile = fileopenbox(msg='Choose the correct File', title='Matrix Input
File')
input = file(thisfile,'r')

header = string.split(string.strip(input.readline()),',')
header.extend(['55FirstName',
'55Intial','55LastName','55Alias',])

all = input.readlines()
input.close
input = None
matrix = {}
for user in all:
user1 = string.split(string.strip(user),',')
user1.extend(['None']*4) <-------------------------I would like to
None or better NULL this instead of string it
user1 = dict(zip(header,user1))
matrix[user1['OldNTLogon']] = user1

mychoice = choicebox(choices=matrix.keys())
user1 = matrix[mychoice]

alltogether = ''

for KeyName in user1.keys():
if alltogether == '':
alltogether = KeyName + '=' + ' ' + user1.get(KeyName) + '\n'
else:
alltogether = alltogether + KeyName + '=' + user1.get(KeyName) +
'\n' <------- error 'can not cat None with a str' or something like that

msgbox(alltogether,'User Matrix for '+ mychoice )

msgbox('The End')
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top