×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

PYTHON; 'invalid literal for float<>: "X" ERROR ???

PYTHON; 'invalid literal for float<>: "X" ERROR ???

PYTHON; 'invalid literal for float<>: "X" ERROR ???

(OP)
Hi there I am a newbie to python.I have attached a link to the script and the input file which it uses.When I run the script in abaqus command, I get the following error :File"nodes-els.py",line 9,in?
textlines.append<map<string.atof,string.split<line,','>>>
file "python/lib/string.py"line 200,in atof
valueerror:invalid literal for float <> :"X"

how can I address this error . . .
thank you melody

the script:
http://www.zshare.net/download/23841396220f15/
the input file:
http://www.zshare.net/download/2384160eea9b4e/

RE: PYTHON; 'invalid literal for float<>: "X" ERROR ???

The first line of "source.txt" contains:
"X","Y","Z"
Obviously, these cannot converted to float.
Hence, the error given by the code on line 9:
valueerror:invalid literal for float <> :"X"

RE: PYTHON; 'invalid literal for float<>: "X" ERROR ???

(OP)
Hi Xerf
thank you for your help, I deleted the X,Y,Z line from the source file
I have another problem further down the script . . .
"line 31, in <module>
tempList.append (i+1,textLines[i])
TypeError:append() takes exactly one argument (2 given)"
any help would be appeciated
melody

RE: PYTHON; 'invalid literal for float<>: "X" ERROR ???

TypeError:append() takes exactly one argument (2 given)"

The "append(value)" method takes one argument 'value' and appends it at the end of the list. The index is not necessary.

 
You might be interested in the "insert(index,value)" method.

RE: PYTHON; 'invalid literal for float<>: "X" ERROR ???

(OP)
Hi Xerf
thank you for your help
I made the changes you suggested, which resolved the problem.
I have another error message further down the script,
",line 39,in?
ycoordjs=newList[j][0][1][1]
TypeError:unscriptable object"
how can I go about resolving this . . .
melody

RE: PYTHON; 'invalid literal for float<>: "X" ERROR ???

before:
ycoordjs=newList[j][0][1][1]

put:
print newList[j]
print newList[j][0]
print newList[j][0][1]

and see if that is what you expect to find at that combination of indices.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources