Newbie Question Import Question Follow
I am a newbie to PyCharm. I have wrote a simple program to open a serial port and send two characters. This program work perfectly as long as all code is in one file. But if I put my function in a second file junk2.py I get a unused import message in PYCharm (Via Grayed out import statement). Do I need to tell PyCharm where to find this file?
Thanks In advance. Here is my code.
Yours Truly,
Neal
I called the files junk1.py and junk2.py
This is junk1.py:
__author__ = 'nealzipper'
import serial
import junk2 # This is grayed out in PyCharm
ser = serial.Serial('/dev/cu.KeySerial1', 9600, timeout=1)
turnoff(2)
x=0
This is junk2.py
__author__ = 'nealzipper'
def turnoff(numb):
global ser
# Turn off relay code goes here
print "Relayoff:", numb
ser.write(chr(254))
ser.write(chr(0+numb))
return
Thanks In advance. Here is my code.
Yours Truly,
Neal
I called the files junk1.py and junk2.py
This is junk1.py:
__author__ = 'nealzipper'
import serial
import junk2 # This is grayed out in PyCharm
- Define ser as global
ser = serial.Serial('/dev/cu.KeySerial1', 9600, timeout=1)
turnoff(2)
- Wait forever
x=0
This is junk2.py
__author__ = 'nealzipper'
def turnoff(numb):
global ser
# Turn off relay code goes here
print "Relayoff:", numb
ser.write(chr(254))
ser.write(chr(0+numb))
return
Please sign in to leave a comment.
I new to an IDE an I thought I had setup issues.
Thanks In advance.
Yours Truly,
Neal
I called the files junk1.py and junk2.py
This is junk1.py:
__author__ = 'nealzipper'
import serial
import junk2 # This is grayed out in PyCharm
- Define ser as global
global serser = serial.Serial('/dev/cu.KeySerial1', 9600, timeout=1)
junk2.turnoff(2)
- Wait forever
while True:x=0
This is junk2.py
__author__ = 'nealzipper'
def turnoff(numb):
global ser
# Turn off relay code goes here
print "Relayoff:", numb
ser.write(chr(254))
ser.write(chr(0+numb))
return