Class method for beginners in python [closed]

can someone PLEASE explain how to use class methods between the class call. We are currently making a tic tac toe game that requires a 3X3 grid, and we want to make a list of list with designated numbers, which will be replaced with either an X or an O in later versions.

Again, for now, I just want to make a 3X3 grid, including the class method call somehow with this format: @… def example

Wall Printing Exercise (Python)

I have to figure out the following question. Any help/suggestions would be appreciated.

Printing a Wall

Desired output for a 3 x 3 wall

|||| ||||| ||||

We refer to the output above as a 3 x 3 wall – meaning it has a length of three bricks and a height of three bricks. Notice that the middle row is “offset,” beginning and ending with a “half brick.” Below are listed properties of a valid wall: • The rows are made up only of underscore ( ) and pipe (|) characters, • The bottommost row is never offset, • Each row above the bottom should alternate between being offset and normal, • The top of the wall is made up of underscores, expect for one space at the very beginning and end. 1 Tasks 1. Complete the method stub print wall one(). This should print out the given 3 x 3 wall as output, line by line. 2. Complete the method stub print wall two(). This also should print out the 3 x 3 wall; however, you should use variables to reduce the amount of code. 3. Complete the method stub print wall three(length, height). This should allow the user to print a wall of any given nonzero integer length and height. For example, see the 4 x 8 and 8 x 4 walls below. print_wall_three(4, 8)

|||||| ||||| |||||| ||||| |||||| ||||| |||||| ||||| print_wall_three(8, 4)

|||||||||| ||||||||| |||||||||| |||||||||

Python vs Java for Neural Network

I’m trying to work on a side project for fun and although my primary field of expertise is finance and econ, I have some background in python and java. I wanted to create a simple neural network program that predicts the future value of stocks based on several variables (historical data, breaking news, etc) and I was wondering if my time is better spent honing my skills in Java or Python for the above program.

Thanks in advance!

Staff of the Python: Can the owner communicate with the snake?

My character just got a Staff of the Python. He has been using his familiar (owl) and a friendly pseudodragon as a little army. I’m thinking of using the snake as an ally as well–but there’s no description of how much the snake can communicate with the player, if it can at all. Does anyone have any idea of guidelines for this?

From the item description:

You can use an action to speak this staff’s command word and throw the staff on the ground within 10 feet of you. The staff becomes a giant constrictor snake under your control and acts on its own initiative count. By using a bonus action to speak the command word again, you return the staff to its normal form in a space formerly occupied by the snake.

On your turn, you can mentally command the snake if it is within 60 feet of you and you aren’t incapacitated. You decide what action the snake takes and where it moves during its next turn, or you can issue it a general command, such as to attack your enemies or guard a location.

If the snake is reduced to 0 hit points, it dies and reverts to its staff form. The staff then shatters and is destroyed. If the snake reverts to staff form before losing all its hit points, it regains all of them.

It doesn’t really mention any communication, other than issuing general commands. Can it keep watch overnight, if I tell it to wake me up if it sees any enemies? Can I have it scout ahead, as long as it’s within 60 feet?

Python Pandas to sqlite

Hello I am new I had a question so I am trying to create a simple api using flask ..

the data I have is in CSV and I want to import it in to SQLlite file .. which I have done. and can access the data after I data is loaded and I have conformed there is data. I try and get python to reflect the class .. as I need to confirm its there for flask ..

below is what I type.

Python:  Base = automap_base() Base.prepare(engine, reflect=True)  Base.classes.keys() 

I get nothing know why I am getting nothing I its because there is no class set up before I load the data using pandas ..

below is the code I use to load the data to sqlite;

Base = declarative_base() engine = create_engine("sqlite:///countrytwo.sqlite") Base.metadata.create_all(engine)  file_name = 'us.csv' df=pd.read_csv(file_name)  df.to_sql('us',con=engine, index_label='id', if_exists='replace')  ## then to conform theirs data I do below ## print (engine.table_names())   

so do I know I need to set up the class first then load the data in to the sqlite file .. one does any one have a good webiste to do this ..

I would love a clue lead me to the answer but maybe not give me the answer .. if this is unclear let me know I can load more code. thank you.

Exploiting python pickle.loads to execute arbitrary code

I am trying to solve a challenge where I need to exploit python pickle library to execute malicious code.

This is the original code that came as a file

import pickle import time  function_shield.configure({    "policy": {        # 'block' mode => active blocking        # 'alert' mode => log only        # 'allow' mode => allowed, implicitly occurs if key does not exist        "outbound_connectivity": "block",        "read_write_tmp": "block",        "create_child_process": "block",    },    "token": "XXXXXXXX",    "disable_analytics": "true" })  def clock_page(past):    html = '<!DOCTYPE HTML>'\            + '<HTML>'\            + '<HEAD>'\            + '<TITLE>Timer</TITLE>'\            + '<LINK rel="stylesheet" href="">'\            + '<STYLE>'\            + 'body{background: black;}'\            + '.clock{position: absolute; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); color: #17D4FE; font-size: 60px; font-family: Orbitron; letter-spacing: 7px;}'\            + '</STYLE>'\            + '</HEAD>'\            + '<BODY>'\            + '<DIV id="timer" class="clock" onload="showTime()"></DIV>'\            + '<SCRIPT>'\            + 'function showTime(){'\            + 'var future = / 1000 | 0;'\            + 'var delta = future - ' + past + ';'\            + 'var time = delta.toString();'\            + 'document.getElementById("timer").innerText = time;'\            + 'document.getElementById("timer").textContent = time;'\            + 'setTimeout(showTime, 1000);'\            + '}'\            + 'showTime();'\            + '</SCRIPT>'\            + '</BODY>'\            + '</HTML>'    return html  class Epoch(object):    def __init__(self, timestamp):        self.ts = timestamp  #{Secret_code_Here}  def lambda_handler(event, context):    if (('multiValueHeaders' in event.keys()) and (json.dumps(event['multiValueHeaders']) != 'null')):        if ('cookie' not in event['multiValueHeaders'].keys()):            url = event['requestContext']['path']            epoch = Epoch('{:d}'.format(int(time.time())))            cookie = base64.b64encode(pickle.dumps(epoch))            return {                'isBase64Encoded': 0,                'statusCode': 302,                'headers': {                    'Content-Type': 'text/html; charset=utf-8',                    'Set-Cookie': cookie, # Server time may be different to browser time!                    'Location': url                },                'body': ''            }    epoch = pickle.loads(base64.b64decode(event['multiValueHeaders']['cookie'][0]))    return {        'isBase64Encoded': 0,        'statusCode': 200,        'headers': {'Content-Type': 'text/html; charset=utf-8'},        'body': clock_page(epoch.ts)    } 

There is epoch = pickle.loads(base64.b64decode(event['multiValueHeaders']['cookie'][0]))

It extracts the cookie, base64decodes it and finally unpickles. During unpickling we have to execute the malicious code so that it reads the source code of the file.

Later the value of epoch.ts is used.

The cookie generated by the server : gASVNgAAAAAAAACMD2xhbWJkYV9mdW5jdGlvbpSMBUVwb2NolJOUKYGUfZSMAnRzlIwKMTU3NzEwMTU4NZRzYi4=

When I try unpickling , it throws an error ModuleNotFoundError: No module named ‘lambda_function’. I tried using pickletools module to see the differences too.

What I know is I need to put the code inside _ reduce _ so that when the code is unpickled. It gets executed.

I have tried using the following code to get an exploit cookie. It works locally but it does not work with server instead shows internal server error. So, is there anything I am missing? How do I develop an exploit for this?

    def __init__(self, timestamp):         self.ts = timestamp      def __reduce__(self):         ts = '1388907849'         return (self.__class__, (ts, ))   def serialize_exploit():     shellcode = pickle.dumps(fakeEpoch('{:d}'.format(int(time.time()))))     return shellcode  def insecure_deserialize(exploit_code):     print(pickle.loads(exploit_code))   if __name__ == '__main__':     shellcode = serialize_exploit()     print("cookie: ")      print(base64.b64encode(shellcode))     print("Exploit working")     insecure_deserialize(shellcode)