- Posts: 1006
- Thank you received: 449
Using M201 and Python to Lookup a CSV Table File and Using It's Values
- my1987toyota
- Topic Author
- Away
- Platinum Member
-
That said I will give your suggestion a try.
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Away
- Platinum Member
-
- Posts: 1006
- Thank you received: 449
When I tried that I got an error message of " typeError: list indices must be integers, not float"Aciera post=249607 userid=25994Thanks for sharing.
Surely there must be a way to build these commands in just one block using the value of parameter P?
Something along these lines:
self.execute(prefix1 + fdrPos[P][1] + ' ' + fdrPos[P][2] + ' ' + endCoord)
self.execute(prefix2 + fdrPos[P][3] + feeds1)
self.execute(vacOn)
self.execute(pTime)
self.execute(retract)
self.execute(fdrCycl + P)
I will grant that would have drastically shortened the amount of repetitive code . it may need
to go through some " i = P " type conversion . I will play around with your suggestion and see
what I can come up with. Thank you Aciera.
Please Log in or Create an account to join the conversation.
So now you are the expert, you can do the next step which is to access my credit card processor via their API to avoid having to download the csv file! (I use Odoo ERP for our accounting and its written in Python!)
Python is generally a typeless language but sometimes it needs the type to be defined. Something like:
myint = float(myfloatValue)
Have a read of this. www.w3schools.com/python/python_casting.asp
Also, If the csv file needs to change during run time, you might be better off looking at a sql database (mysql is easy to integrate in python) By definition sql can be modified and queried dynamically.
Please Log in or Create an account to join the conversation.
" typeError: list indices must be integers, not float"
So, your parameter P is of type "float" and to use it in the list indices you need to change that to type "integer", ie whole numbers.
Since you should only be passing whole numbers as parameter P that would not pose a problem and you could just use the int() function.
Being lazy I would try to change
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Away
- Platinum Member
-
- Posts: 1006
- Thank you received: 449
after some fiddling around with it and sorting through errors I have a working code that is substantially shorter then my last.
I will leave the readable text version and the python file in my next post . Have fun with it, I know I did.
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Away
- Platinum Member
-
- Posts: 1006
- Thank you received: 449
the python file
Please Log in or Create an account to join the conversation.