LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-10-2007, 10:31 AM   #1
forsaken_pariah
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?

Thanks-A-Million

Kory X.
 
Old 03-10-2007, 10:48 AM   #2
Dan04
Member
 
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.
 
  


Reply


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 06:42 PM
python os.system arguments randomx Programming 2 03-03-2005 04:54 PM
Optional setting for XServer digitalbrutus Linux - Software 1 10-28-2004 03:40 PM
Python function arguments are dictionaries? johnMG Programming 1 07-24-2004 07:29 PM
optional proxy with squid? Tom Bozack Linux - Networking 2 08-12-2002 03:02 PM


All times are GMT -5. The time now is 04:27 PM.

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