Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Function Call
#1
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
Reply
#2
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]'
>>>
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 752 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how to call an object in another function in Maya bstout 0 2,042 Apr-05-2021, 07:12 PM
Last Post: bstout
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,414 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,156 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,862 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,154 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,038 Jul-27-2020, 04:19 PM
Last Post: buran
  Simple automated SoapAPI Call with single variable replacement from csv asaxty 1 2,056 Jun-30-2020, 06:38 PM
Last Post: asaxty
  Python: Call function with variabele? Ending in error. efclem 5 2,877 Apr-22-2020, 02:35 PM
Last Post: buran
  got SyntaxError while building simple function zarize 2 2,078 Feb-14-2020, 10:51 AM
Last Post: zarize

Forum Jump:

User Panel Messages

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