Articles of the Week

Pubbies of the Week

Is IDLE Good?

Categories: General, Tech | Pubby Cash Received:  10

It comes pre-installed with Python, but many coders just ignore it. Is IDLE worth your time? Well, if you’re a beginner, IDLE would be a great start for you. Although it has just the bare bones, the best place to experiment with Python code is in the interactive interpreter, otherwise known as a shell. The shell is a basic Read-Eval-Print Loop (REPL). It reads a Python statement, evaluates the result of that statement, and then prints the result on the screen. Then, it loops back to read the next statement. The Python shell is an excellent place to experiment with small code snippets. You can access it through the terminal or command line app on your machine, however, all of the text will be a single color and it will be hard to understand the outputs. You can simplify your workflow with Python IDLE, which will immediately start a Python shell when you open it. IDLE will automatically highlight the keywords and other python commands so you will know without a doubt what you are looking for. Every programmer needs to be able to edit and save text files. Python programs are files with the .py extension that contain lines of Python code. Python IDLE gives you the ability to create and edit these files with ease. Python IDLE also provides several useful features that you’ll see in professional IDEs, like basic syntax highlighting, code completion, and auto-indentation. Professional IDEs are more robust pieces of software and they have a steep learning curve. If you’re just beginning your Python programming journey, then Python IDLE is a great alternative!...  Read more

Write and Read a Dictionary into TXT file in Python

Categories: Tech | Pubby Cash Received:  0

I've been exploring an elegant way of exporting/importing a dictionary into/from an external TXT file for recording purposes. Say I have a dictionary with stocks codes and prices, and the dictionary's name is called stocks, and this dictionary is stored in a py file called rank.py. The txt file I've like to export to is 'stocks.txt'. The relative path from the operating py file to the txt file is 'static/stocks.txt'. To export the dictionary from the py file into the txt file, this code will be neat: from rank import stocks with open('static/stocks.txt', 'w') as f: print(stocks, file=f) To read the dictionary from the txt file, use this code: with open('static/stocks.txt', 'r') as f: content = f.read() stocks = eval(content) When it comes to the operation in flask route functions, I found it worked totally different with regard to the file path of the txt file. An error of "no file/file directory" keeps blowing off the code. Eventually I figured out that the file path should be written in a different way with the following code: import os from flask import current_app f_path = os.path.join(current_app.root_path, 'static/stocks.txt') with open(f_path, 'r') as f: content = f.read() stocks = eval(content) What a tricky debugging issue! ...  Read more

The Alexa

Categories: Tech | Pubby Cash Received:  0

Are you a person who forgets things a lot? Well, Alexa can help you. This tool is made by Amazon. It is helpful and safe. First, it is helpful because you can do so many things with it. For example, you don't have your phone with you, so you can tell Alexa to call whoever you want. Also, you can ask Alexa questions, such as what is the weather today, or what is the time. Furthermore, you can tell it to set reminders, like to wake up at seven in the morning. This just proves how helpful it is. Also, it is safe. After all, you can press the mic off button to disconnect the microphones. Not only that, but you can tell it to turn on the porch lights or set the thermostat 72. Overall, Alexa is a great product to buy. ...  Read more

The Ultimate Coding Experience

Categories: General, Tech | Pubby Cash Received:  0

Many programmers struggle with reading their code because they don’t have the right font. That’s right, just the shape of some letters could throw at you a super annoying bug that will take two hours to fix. Especially when it comes to the shapes of the letter “O” and the number “0”. They’re both round, and sometimes, it can be very difficult to tell them apart. That’s why you need the correct font that will make you instantly tell the difference between those two. Menlo Regular is an excellent font in this situation. It is very easy to tell the difference between the zero and the ‘O’ because there is a slash in the zero. All of the characters are extremely easy to read and the letters line up when you are doing some serious coding because it is a monospaced font. That means that each character takes up one space. When it comes to indentations and precision coding, monospaced fonts are the way to go. Other good choices include Consolas, Courier, Lucida Console, Monaco, and Inconsolata. Choose your favorite and you’ll be on your way to an exciting coding experience!...  Read more

The Raffle Game

Categories: Tech | Pubby Cash Received:  10

It would be fun to find ways for pubbies to spend and earn Pubby Cash. Purchasing a raffle ticket is one of the ways the admin team has developed. Let me explain how this is realized. 1. Create a table in the database with sufficient columns to record all relevant raffle related information. The columns are: raffle id, date raffle opened, date raffle closed, current raffle pool, max raffle pool, transaction activities (a list with player id), winner id, and raffle status. The table should be declared as a model and linked to the code. 2. When a player trying to buy a raffle ticket, the database will be queried for the most recent game. If the most recent game is closed, a new game will be created. When the max raffle pool has reached (100 Pubby Cash) in this case, the status of the game will be changed to a closed state. Random number will be generated to determine who is the winner. 3. Update the database with relevant info. The tables that will be affected are the cash table, message table, user table, and of course the raffle game table. For the cash table, record the purchase transaction details. If a player wins, insert an additional transaction on the amount that he/she won. For the message table, update the table with a new message sent to the winner. For the user table, all players' Pubby Cash balance should be updated. For the raffle game table, the game record should be updated. 4. Generate a plot visualizing the dynamic purchasing activities of pubbies involved in the raffle game. This would require a data visualization module "matplotlib", which will generate a bar chart plotting the number of tickets each pubby purchased on the x axis, and the name of each pubby who purchased ticket(s). Then, a raffle game is all set to go! ...  Read more

1 ... 21 22 23 ... 32

Daily Deals


MECHANICSBURG WEATHER