# Intro to Python ## Week 9 ### Files, file formats and nested data --- ## Agenda - Runestone Ch 11: Files - Runestone Ch 13: Exceptions notes: - [ ] json file with game data - [ ] using dict in classify_text (map words/characters to found categories) - [ ] refactor a game, one variable at a time --- - Data file formats - (py, md, txt, json, csv, ...) - Nested data - (dicts of dicts, lists of lists ...) - Midterm project feedback - functions and modules - ``__name__ == '__main__'`` - `input` - unicode - simple is better than complex - complex is better than complicated --- ## Nested data ### List of lists ```python >>> table = [ ... ['date', 'time', 'name', 'lat', 'lon', 'alt'], ... ['12/25', '23:59', 'NP', '90.00', '0.00', '20'], ] ``` A list of list is a good way to store a table (spreadsheet). --- ### Lists of lists (tables) ```python >>> table = [ ... ['date', 'time', 'name', 'lat', 'lon', 'alt'], ... ['12/25', '23:59', 'NP', '90.00', '0.00', '20'], ] ``` --- ## Data - `.json` - `javascript` data values - `.csv` - **C**omma-**S**eparated-**V**alues_ (tables) - `.tsv` - **T**ab-**S**eparated-**V**alues_ (tables) - `.psv` - **P**ipe-**S**eparated-**V**alues_ (tables) --- ## Human-readable - `.txt` - usually *unstructured* data - `.py` - ?? - `.md` - markdown - `.html` - hypertext mark**up** language - `.xml` - extensible mark**up** language --- ## Midterm project - compose functions into a program - modules are `import`able without running - ``__name__ == '__main__'`` - `input` - unicode - simple is better than complex - complex is better than complicated --- ## Large language models - Why did they make you run laps during sports classes? Going by car is much faster. - Why did they make you write long essays in school if a machine can write you a million essays if you ask it to? - Why would you go to a gym if a robot could be lifting much heavier weights than you can? - Why did you decide to go university if an LLM will give you an answer about any topic in the world? Why are you here? --- ## Skill - None of the skills you have were acquired without having to practice - You learn best when you fail. - You learn even better when you teach. - Become someone who is more than just a copypaster --- ## Enjoyment We don't write software to create software in the same way like we don't cook so that there is food. Otherwise, why don't you just always buy the food mass-produced in a factory somewhere? LLMs can generate a million paintings that look like they are created by an expert artist. Would you visit a gallery with these paintings? Why not? A robot can outperform any athlete. Would you rather watch the human do sports or the robot do sports? Why? Maybe you want your program to be more than something like a cheap T-shirt produced by underpaid labor and discarded the next day? Maybe you want to create something that lasts, which can be maintained, is secure and reliable. --- ## Mathematicians ### 28 Fields Medal winners: > *But solving problems is only a tool and proxy for achieving the primary goal of conceptual understanding and insight. Forgetting this in the world of AI may turn the tool against the primary goal. Indeed, the mass production at faster and faster pace of "true/false" statements could destroy fertile ground instead of breathing life into new ideas.* [https://mathandai.org/](https://mathandai.org/) --- ### Gen AI - productivity & learning 2.5 yr study of 27k Chinese grades 7-12 - "raises homework scores by 18%" - "reduces completion time by 30%" - "lowers monthly exam scores by 20%" - "entrance-exam scores fall by 18 and 24%"
"The Generative AI Learning Penalty: Evidence from Chinese Secondary Education" by David Strömberg, Victor Lei, Yanhui Wu
[https://papers.ssrn.com/sol3/papers.cfm?abstract_id=6868618](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=6868618) --- ## NYC AI Moratorum - Zohan Mamdani forbade AI use for 2 years in elementary school - Parents and teachers want the ban expanded to High School - Parents and teachers want permanent ban - Many schools in US ban cellphones in elementary school - Many schools in US ban cellphones in middle school --- ## LLM exam scores  Figure 2: "The Generative AI Learning Penalty: Evidence from Chinese Secondary Education" by David Strömberg, Victor Lei, Yanhui Wu --- ## Large language models > *We study the impacts of AI coding assistants and agents on software engineering work, using a novel proprietary dataset from an engineering analytics platform, covering 300 million work events – including GitHub coding activity, Jira issues, and Google Calendar events – across 718 firms. […] Both technologies increase coding productivity. However, productivity gains do not fully pass through to changes in software output or employment. For AI agents, this incomplete pass-through reflects a bottleneck from code review: review times increase, a larger share of code updates require revisions, and reviews involve more comments.* "Artificial Intelligence in the Firm: Bottlenecks in Software Production" by Fiona Chen and James Stratton, Harvard University [https://fion.ac/jellyfish.pdf](https://fion.ac/jellyfish.pdf) --- ## Large language models The best thing about computers is that they will always do the same thing given the same input. They cannot do anything else because what they do is determined by an algorithm. Did software become better, more reliable or more secure now that so many started using LLMs? No, now we just have more badly maintained software. --- ## Hello world?  It compiles and prints `hello world` -- C++ ignores the whitespace. ```cpp #include
int main() { std::cout << "hello world" << std::endl; return 0; } ``` --- Slides adapted from Johannes Schauer Marin Rodrigues, *Programming 1 Lecture Notes*, THWS, WS 2026/27 --- ## Midterm project - composition - create functions - use (run) functions in the order things need to happen - modules are `import`able without running - ``__name__ == '__main__'`` - `input` - unicode - simple is better than complex - complex is better than complicated --- ## How do you write code? - [ ] Have you used runestone to get ideas or copy/paste code - [ ] What other "outside" resources have you used? (docs.python.org, pypi.org, ) - [ ] What tools have you discovered? (PyDroid, ) --- ## Cybersecurity Research - Search the internet for security problems - past few weeks - affecting your safety - something you can fix --- ## What problems did you find - PHP server problem - password manager - TFA/SMS authentication phishing - clicking wrong link - weak passwords - AI agents weakening internal security - data extortion - sharing one-time-codes - AI in linux - openai found 70% --- ## emudhra - - decryption password for internet --- ## Runestone - unexpected indent line 56 --- ### --- ## Cybersecurity Research Search the internet for recent problems with the internet 1. [emudhra]https://emudhra.we-have-a-problem.com/#check 2. upgrade php after 10 pm tonight on all your containers/servers 3. restart your phone after every Signal voice or video chat