Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-10-2007, 09:31 AM   #1
LQ Newbie
Registered: Jan 2007
Location: Prattvegas
Distribution: Debian Etch, Kubuntu Feisty
Posts: 16

Rep: Reputation: 0
Question Optional arguments in Python

I was wondering if there were a way to make arguments listed before *args optional in Python, so that they keep their default values unless I explicitly tell the function that value should be something else. For example, if I define a funtion like this...

def fwritef(file, mode='UTF8', *args, **keywords):

would there be a way to keep mode='UTF8' until I tell it I want it to be something else, so that fwritef('myfile.txt', 1, 2, 3) would keep mode='UTF8' but something like fwritef(file='myfile.txt', mode='ANSI', 1, 2, 3) wouldn't?


Kory X.
Old 03-10-2007, 09:48 AM   #2
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
fwritef('myfile.txt', *(fwritef.func_defaults + (1, 2, 3)))

There might be an easier way, but I can't think of it.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
x11 libraries are optional? kgustaf Linux - Software 4 09-06-2005 05:42 PM
python os.system arguments randomx Programming 2 03-03-2005 03:54 PM
Optional setting for XServer digitalbrutus Linux - Software 1 10-28-2004 02:40 PM
Python function arguments are dictionaries? johnMG Programming 1 07-24-2004 06:29 PM
optional proxy with squid? Tom Bozack Linux - Networking 2 08-12-2002 02:02 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:09 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration