Caesar Cipher Function in Python
location: linuxexchange.com - date: February 23, 2015
I'm trying to create a simple Caesar Cipher function in Python that shifts letters based on input from the user and creates a final, new string at the end. The only problem is that the final cipher text shows only the last shifted character, not an entire string with all the shifted characters.
Here's my code:
plainText = raw_input("What is your plaintext? ")
shift = int(raw_input("What is your shift? "))
def caesar(plainText, shift):
for ch in plainText:
stayInAlphabet = ord(ch) + shift
if stayInAlphabet > ord('z'):
stayInAlphabet -= 26
finalLetter = chr(stayInAlphabet)
cipherText = ""
cipherText += finalLetter
print "Your ciphertext is: ", cipherText
python, os.system() function. howto use python variables?
location: linuxquestions.com - date: July 26, 2007
i would like to do something like this in python:
Running specific function in python script
location: ubuntuforums.com - date: November 26, 2010
Is it possible to run a specific function within a python script from the terminal. For example, if i have abc.py
print "var a is "+a
is there a way to run python abc.py and specify the function xyz from within terminal (but not the python shell)?
Like: $ python abc.py -function xyz("HELLO")
var a is HELLO
except something that works obviously
Quantal, LibreOffice 3.6, Python how to create function/macro
location: ubuntuforums.com - date: November 6, 2012
I cannot figure out how to add function or macro to LibreOffice written in Python.
I read that I should go to Tool -> Macros -> Organize Macro -> Python, but there is only LibreOffice Basic.
I also installed libreoffice-script-provider-python, but Python menu item keeps missing.
I guess it is triviality question, but I cannot google the answer.
Python function to encrypt and decrypt password
location: ubuntuforums.com - date: January 11, 2008
I want to write a password to a configfile but instead of writing the password as plain text i would like to save it in a human unreadable format.
the security doesn't need to be excellent, but the purpose is that users that open the file can not read the password immediately...
the function also has to be able to decrypt the password again so i can use it in my application.
is there any simple python function for this or a project that uses such a fuction?
I don't know how to add a function to a menu Item in glade/python (generated with quickly)
location: linuxexchange.com - date: August 16, 2015
I am trying to add a function to a menu item when clicked I want that function to execute
the application is named Simpleadministration
code that I am using located in the Simpleadministrationwindow.py :
builder = Gtk.Builder()
warning in the terminal:
WARNING:simpleadministration_lib: connect_signals() 'expected handler 'on_account_add_menu_item_activate' in /home/ami/simpleadministration/simpleadministration/SimpleadministrationWindow.py'
I don't know exactly what is going wrong can someone help me?
(Menu structure with selected item from SimpleadministrationWindow.ui)
http://i57.tinypic.com/2s6pstx.png (cannot upload with reputation lower than 10)
trying to give as much information as possible
How to add a timeout to a function in Python
- date: July 10, 2010
Many attempts have been made in the past to add timeout functionality in Python such that when a specified time limit expired, waiting code could move on. Unfortunately, previous recipes either allowed the running function to continue running and consuming resources or else killed the function using a platform-specific method of thread termination. The purpose of this wiki is to develop a cross-platform answer to this problem that many programmers have had to tackle for various programming projects.
#! /usr/bin/env python
"""Provide way to add timeout specifications to arbitrary functions.
There are many ways to add a timeout to a function, but no solution
is both cross-platform and capable of terminating the procedure. This
module use the multiprocessing module to solve both of those problems."""
__author__ = 'Stephen "Zero" Chappell <[email protected]
__date__ = '11 February 2010'
Help me to port this NetHack function to Python please!
location: linuxexchange.com - date: June 3, 2009
I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in hacklib.c.
I have tried to simply copy the corresponding function from the NetHack code but I don't believe I am getting the correct results.
The function which I have written is phase_of_the_moon().
The functions position() and phase(), I found on the net, and I am using them as an indication of the success of my function. They are very accurate and give results which approximately match the nethack.alt.org server (see http://alt.org/nethack/moon/pom.txt). What I am after however is an exact replication of the original NetHack function, idiosyncrasies intact.
I would expect my function and the 'control' function to give the same moon phase at least, but currently they do not and I'm not sure why!!
Any help would be appreciated,
Here is the NetHack code:
* moon period = 29.53058 days ~= 30, year = 365.2422 days
* days moon phase advances on first
How can I make a chain of function decorators in Python?
location: linuxexchange.com - date: April 17, 2015
How can I make two decorators in Python that would do the following?
which should return
I'm not trying to make HTML this way in a real application, just trying to understand how decorators and decorator chaining works.
webkit (webkitgtk3) function prototype as seen in python from pywebkit
location: linuxexchange.com - date: May 28, 2014
pywebkit makes calls from python into webkit by introspection. The prototype of called functions are bound at runtime. A little problem for developers is that you will not see the prototype in source code. How do you find the function prototype? Specifically "add_event_listener"?
This piece of python code is from pyjs.org pyjs/runners/giwebkit.py:
702 def addEventListener(self, element, event_name, cb):
703 listener = Callback(element, cb, False)
704 element.add_event_listener(event_name, listener, False)
When running on fedora 20 it gives this error:
File "/.../pyjs/runners/giwebkit.py", line 704, in addEventListener
element.add_event_listener(event_name, listener, False)
TypeError: add_event_listener() takes exactly 5 arguments (4 given)
How to find out what are the arguments and their types passed to function "element.add_event_listener()"? Can I insert a piece of python code to print it out?
I searched to find the prototype to add_event_listener(), b
Page: 1 2 3 4 5 6 7 8 9 10