Python Forum
With pyCharm how to run(build) the whole(3 files)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
With pyCharm how to run(build) the whole(3 files)
#11
I wrote a project with 4 files. The first is only for the imports. The following 3 files, hundling numbers, factorial, and one sort. The whole works well. Here is the code of the first file...................:................................................................................
# flle1.py

import file2
import file3
import file4


def foo1():
    print("This is function foo1 from file1.py")
    file2
    file3
    file4


foo1()
file2
file3
file4
Reply
#12
I give up, maybe my English is not that good after all... Does anyone want to try and explain better than me?
Reply
#13
(Apr-08-2017, 08:33 AM)sylas Wrote: I wrote a project with 4 files. The first is only for the imports. The following 3 files, hundling numbers, factorial, and one sort. The whole works well. Here is the code of the first file...................:................................................................................
# flle1.py

import file2
import file3
import file4


def foo1():
    print("This is function foo1 from file1.py")
    file2
    file3
    file4


foo1()
file2
file3
file4

What do you think lines 10, 11, 12, 16, 17, and 18 do?  Because they're not actually doing anything at all.
Reply
#14
You are right ! I only left the 3 lines with the imports and it works the same. Thank you very much.
Reply
#15
(Apr-10-2017, 10:34 AM)sylas Wrote: You are right ! I only left the 3 lines with the imports and it works the same. Thank you very much.

Man, in simple terms the idea of import is to make functions, names, classes, etc from one module accessible in another module. Very basic explanation but for so far it's good enough. The execution of the code from the imported module is more or less side effect - only because your code is not properly organised in a first place. Your code or specific part of it (e.g. specific function) should be executed only when you call it. Let's say you want to execute code from another module more than once in different places in the flow of your program? What will you do - will you import it second time? And what if you want only part of that code executed?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie question about switching between files - Python/Pycharm Busby222 3 1,376 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  Importing files with Pycharm sylas 3 12,564 Jan-14-2018, 09:31 AM
Last Post: sylas

Forum Jump:

User Panel Messages

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