2014-01-30 15:29:21 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								IN:  python.syntax  
						 
					
						
							
								
									
										
										
										
											2014-02-03 05:28:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								USING:  hashtables  python.syntax  help.markup  help.syntax  ;
  
						 
					
						
							
								
									
										
										
										
											2014-01-30 15:29:21 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  PY-FROM:  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $syntax "PY-FROM: module => name-effects ;"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { "module"  "fully qualified name of a python module"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { "name-effects"  "pairs of names and effect declarations of bindings to import"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "Creates factor words that maps to the given python objects." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { $code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "PY-FROM: os.path => isfile ( path -- ? ) splitext ( path -- root ext ) ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-23 12:43:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  PY-QUALIFIED-FROM:  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $syntax "PY-QUALIFIED-FROM: module => name-effects ;"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { "module"  "fully qualified name of a python module"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { "name-effects"  "pairs of names and effect declarations of bindings to import"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "Like "  { $link \ PY-FROM:  } " except all words are created with module as the given prefix." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 15:29:21 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								HELP:  PY-METHODS:  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $syntax "PY-METHODS: class => name-effects ;"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { "class"  "name of a class to associate the bindings with"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { "name-effects"  "pairs of names and effect declarations of methods to create"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "Creates factor words that acts as properties and getters and can work on any python object." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { $code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "PY-FROM: zipfile => ZipFile ( name mode -- file ) ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "PY-METHODS: ZipFile => namelist ( self -- names ) ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "! Then use the declarations like this" 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 12:39:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "\"name-of-zip.zip\" >py \"r\" >py ZipFile namelist py>" 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 15:29:21 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-03 05:28:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ARTICLE: "python.syntax"  "Syntax for python calls from factor" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"The "  { $vocab-link "python.syntax"  } " vocab adds syntax to factor to make calls from factor to python natural and intuitive."  
						 
					
						
							
								
									
										
										
										
											2014-10-23 12:43:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections \ PY-FROM:  \ PY-QUALIFIED-FROM:  \ PY-METHODS:  }
							 
						 
					
						
							
								
									
										
										
										
											2014-02-03 05:28:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$nl
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $examples "Here is how you bind and call a method namelist on a ZipFile instance created by importing the zipfile module:" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { $code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "PY-FROM: zipfile => ZipFile ( name mode -- file ) ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "PY-METHODS: ZipFile => namelist ( self -- names ) ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "! Then use the declarations like this" 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 12:39:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "\"name-of-zip.zip\" >py \"r\" >py ZipFile namelist py>" 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-03 05:28:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "In python, a method or function takes keyword arguments if its last parameter starts with \"**\". If the name of the last argument to a declared function is \"**\" then a "  { $link hashtable } " can be sent to the function:" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  { $code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "PY-FROM: datetime => timedelta ( ** -- timedelta ) ;" 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-05 13:13:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "PY-METHODS: timedelta => seconds ( self -- n ) ;" 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 12:39:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "H{ { \"hours\" 99 } { \"minutes\" 33 } } >py timedelta $seconds py> ." 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-03 05:28:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "12780" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;