Search found 5 matches
- Wed Jan 19, 2022 11:00 pm
- Forum: General Discussion and Questions
- Topic: Read csv and cast str to int
- Replies: 10
- Views: 12726
Re: Read csv and cast str to int
repr() allows me to print some additional characters that are hidden by print(). For example the '\r' character for new lines will not be shown with print with would be shown with print(repr()). I think the problem is related so some kind of hidden characters that repr() also does not print. I solve...
- Wed Jan 19, 2022 9:29 pm
- Forum: General Discussion and Questions
- Topic: Read csv and cast str to int
- Replies: 10
- Views: 12726
Re: Read csv and cast str to int
The conversion to str() with the input already of type str() works without error. When I tried the binascii.hexlify() with the input as a string, I got the following error:
TypeError: a bytes-like object is required
However I also get this error for any arbitrary string like '45' that I input.
TypeError: a bytes-like object is required
However I also get this error for any arbitrary string like '45' that I input.
- Wed Jan 19, 2022 2:55 am
- Forum: General Discussion and Questions
- Topic: Read csv and cast str to int
- Replies: 10
- Views: 12726
Re: Read csv and cast str to int
If I define and declare a string in a line like a = ‘7’, I can cast to int with int(a) and this works properly. However, if I read the string in from a csv file in the way that I described, I can get to the point where I have a string ‘7’ that prints identically to the variable a (I used repr to ver...
- Tue Jan 18, 2022 8:48 pm
- Forum: General Discussion and Questions
- Topic: Read csv and cast str to int
- Replies: 10
- Views: 12726
Re: Read csv and cast str to int
The loading of the csv file works properly up until the point when I try to convert a string like '7' into an integer with int()
- Tue Jan 18, 2022 4:14 pm
- Forum: General Discussion and Questions
- Topic: Read csv and cast str to int
- Replies: 10
- Views: 12726
Read csv and cast str to int
I have calibration data stored in a .csv file. It is structured liked: 1,2,3,4,5 6,7,8,9,10 ... I am reading the file into a Python script like: f = open("filename.csv", "r") data = f.read() f.close() data = data.replace('\r','').split("\n") # Now I'm trying to convert the strings to ints, but I can...