Newbie Question Import Question

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
  1. Define ser as global
global ser
ser = serial.Serial('/dev/cu.KeySerial1', 9600, timeout=1)
turnoff(2)

  1. 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
1 comment
Comment actions Permalink
Sorry I found my mistake. Silly. junk2.turnoff(2) fixed my issue.

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
  1. Define ser as global
global ser
ser = serial.Serial('/dev/cu.KeySerial1', 9600, timeout=1)
junk2.turnoff(2)

  1. 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
0

Please sign in to leave a comment.