Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with variables
#1
>Hi All,
I am trying to build a function to write text to a 20X4 LCD.
I have imported the appropriate driver and defined the name of the lcd.
lcdBB=I2C_LCD_driver_twoLCD.lcd(0x26)
Now i want to use a variable that is given as a parameter in the def of the function: side.
Side can be BB (port) or SB (starbord).
i now do:
dspy='lcd'+side
which results in:
>>> dspy
'lcdSB'
To write a line to the lcd i do:
>>> lcdBB.lcd_display_string(boord+' pomp OFF',4)
that works fine so i thought, can i construct the 'lcdBB" from the parameters of the function and thus i did:
>>> dspy.lcd_display_string(boord+' pomp OFF',4)
Error:
Traceback (most recent call last): File "<pyshell>", line 1, in <module> AttributeError: 'str' object has no attribute 'lcd_display_string'
With the above AttributeError as result.
Apparently i can not substitute the pre-defined 'lcdBB' by the constructed string dspy=('lcd'+side).

Can anyone advise if there is a way to do what i want (if possible at all).

Rgds Steffen
Reply
#2
which package do you use?
please post the whole code in python tags.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Hi Buran,
Thanks for your reaction.
I dont have a complete program -if thats what you mean by package- yet.
If by package you refer to driver, its the published
import I2C_LCD_driver.py
modified to
!2C_LCD_driver_twolcd.py
to accept a parameter as the address of the lcd (0x26 or 0x27).
I thought it best to get the individual components working first.
Then i will build the function i am looking for.
No use building a house when you don't know if the bricks are OK Smile

By the way Buran,
i received a notice that you fixed the error tags.
Apparently i have done something wrong or made an error i am not aware of.
Could you please tel what i did wrong?

greetings Steffen
Reply
#4
(Jul-14-2018, 08:28 AM)Steffenwolt Wrote: By the way Buran,
i received a notice that you fixed the error tags.
Apparently i have done something wrong or made an error i am not aware of.
Could you please tel what i did wrong?
In the original post the traceback was in python tags. I changed these to error tags, so it now looks like error not code.

As to the rest - I'm not sure I understand what you are doing/what have you done..
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
I'll start a new topic.
I think i lost my train of thoughts because i am not sure what it was i was truing to do.

Tks sofar, Steffen
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem using exec to save local variables dkarl 0 1,801 Dec-01-2019, 08:52 AM
Last Post: dkarl
  Problem with variables JCB 3 2,315 Nov-13-2019, 07:20 PM
Last Post: the_ophidian_order
  A problem with defining variables meru120 5 3,411 Apr-16-2019, 03:13 PM
Last Post: buran
  [split] Problem using global variables RedSkeleton007 1 2,662 Nov-10-2017, 09:13 PM
Last Post: sparkz_alot
  Vending Machine Program: Problem with variables icabero0225 2 8,520 Jun-08-2017, 11:04 AM
Last Post: buran
  MySQLdb, problem with query with user-defined variables buran 6 6,412 Feb-03-2017, 06:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020