views:

46

answers:

5

for this,

import os.path

def f(data_file_path=os.path.join(os.getcwd(),'temp'),type):
    ...
    return data

I get this,

SyntaxError: non-default argument follows default argument

Is there a way to make this work or do I have to define a variable such as,

rawdata_path = os.path.join(os.getcwd(),'temp')

and then plug that into the function?

A: 

You have to switch the order of the arguments. Mandatory arguments (without default values) must come before arguments with set default values.

ntownsend
+1  A: 

Move type before data_file_path

def f(type,data_file_path=os.path.join(os.getcwd(),'temp')):

Assigning values in the function parameter called default arguments, those should come afther non-default arguments

S.Mark
A: 

Rearrange the parameters:

def f(type, data_file_path=os.path.join(os.getcwd(),'temp')):
    pass

The reason for this is, that arguments with default values can be omitted.
But of you call f('foo'), it is not know if you want to set the type and omit data_file_path or not.

Felix Kling
A: 

Arguments with a default value should be placed after all arguments without a default value.

Change it to:

import os.path

def f(type, data_file_path=os.path.join(os.getcwd(),'temp')):
    ...
    return data
Amarghosh
A: 

Never mind.

SyntaxError: non-default argument follows default argument 

refers to the order of the arguments so,

def f(type,data_file_path=os.path.join(os.getcwd(),'temp')):

works!

me newbie

LtPinback