Python Forum
Simple Function Call - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Simple Function Call (/thread-2716.html)



Simple Function Call - PappaBear - Apr-04-2017

Complete Noob to programming.  With that out of the way,  Going into the function does not appear to be happening.

I put a print statement in the "if then" to verify my condition was in fact matching (it is, 35 times).
I commented out that print statement;  I then commented out all the function, and added a very simple print statement.
I get zero output within the function.
Would love to know what I'm missing.

Many Thanks,
PappaBear


original_file = open('c:\\scripts\\original-objects.txt', 'r')
new_file = open('c:\\scripts\\converted-objects.txt', 'w')
print("Prepped both input/output files")
addressword = "object "

def found_new_address_object():
print ("Now in Function")
# commented out conversion steps
# writing out to a new file, etc
return

original_lines = original_file.readlines()

print ("Starting for loop")
for counter in range(len(original_lines)):
if addressword in original_lines[counter]:
#print ("yes on if statement")
found_new_address_object



RE: Simple Function Call - Mekire - Apr-04-2017

Not sure what you are doing, but you don't appear to be calling your function at all; you need parenthesis after it like some_func() even if the function takes no arguments.  Also you need to keep indentation when posting.

>>> def some_func(some_arg):
...     print("In function with argument '{}'".format(some_arg))
...
>>> some_func(135)
In function with argument '135'
>>> some_func("spam")
In function with argument 'spam'
>>> some_func([1,2,3])
In function with argument '[1, 2, 3]'
>>>



RE: Simple Function Call - PappaBear - Apr-04-2017

that was it -- I was missing the () when calling the function.. Huge thanks for the quick reply.

for counter in range(len(original_lines)):
       if addressword in original_lines[counter]:
              #print ("yes on if statement")
              found_new_address_object()