I'm having an issue with PySerial and Python (3.3): The code I'm running (for now, this is just a simple test case) is as follows:
which gives the following error:
What's my stupid mistake? I think I've traced this to the fact that PySerial's readline is returning a binary string (new in python 3?) and that the string operation 'split' is failing when run against a binary string - it works fine if you run this:
Which gives the expected:
Method 1: Convert month name to number with formula. Type this formula =MONTH(DATEVALUE(A1&' 1')) ( A1 indicates the cell that you want to convert the month name to number, you can change it as you need) into a blank cell, and press Enter key. Generate a 16 character unique key in java. Ask Question. Key should be unique as it will be inserted into db as primary key eventually. I want with less effort if this problem is alredy solved one. Can I use MessageDigest for generating a 16 char unique key out of few alphanumeric fields? – Swagatika Oct 8 '12 at 13:16.
But then running:
gives the error above. Is there a different readline method to use? should I code my own with read (and just read until it sees /r/n) or can I easily convert to a string that will satisfy str.isalnum()? Thanks!
The quickest solution will be to use a python module called binascii that has a selection of functions for converting the binary string to an ascii string: http://docs.python.org/2/library/binascii.html
EDIT:The b means that it is a byte array and not a literal string. The correct way to convert the byte array to a litteral string will be to use the str() function:
str(b'1234, asdf, 456, jkl', 'ascii').split(',')
this gives the output you want:['1234', 'asdf', '456', jkl']
I hope that helps!
EnthralEnthral
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged stringserial-portpyserialpython-3.3 or ask your own question.
Active5 years, 1 month ago
I use excel to correlate key credentials. My keys are in this format xxxx-xx, where 'x' can be a letter or number. Is there any way to format the cells so that I don't have to type the '-' every time? and it will sort properly?
robrob
2 Answers
I don't think this is possible directly (see the documentation on formats in Excel).
However, you could use a formula like =CONCATENATE(LEFT(A1,4),'-',RIGHT(A1,2)) to create a formatted column.
D SchlachterD Schlachter
Very similar to the above, but in some sense 'easier' to change.
Convert A Alphanumeric String Into A Serial Key Generator
WARNING, untested code; it works in open LibreOffice though ;-).
Press ALT-F11
Insert a module, then type this into the editor window:
Then type:
Convert A Alphanumeric String Into A Serial Keys
in any cell, replace VALUE by either a literal string, cell reference or formula building a string.