MediaWiki API result

This is the HTML representation of the JSON format. HTML is good for debugging, but is unsuitable for application use.

Specify the format parameter to change the output format. To see the non-HTML representation of the JSON format, set format=json.

See the complete documentation, or the API help for more information.

{
    "batchcomplete": "",
    "continue": {
        "gapcontinue": "Reflection_and_Iteration",
        "continue": "gapcontinue||"
    },
    "warnings": {
        "main": {
            "*": "Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."
        },
        "revisions": {
            "*": "Because \"rvslots\" was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used."
        }
    },
    "query": {
        "pages": {
            "1033": {
                "pageid": 1033,
                "ns": 0,
                "title": "Reading and Writing Files in Python",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "THIS ARTICLE IS STILL IN EDITING MODE\n==Reading Files==\nThere are different types of file systems in many operating systems. However, most of the time, you will get off the hook when knowing the two below:\n{| class=\"wikitable\"\n|-\n! File System !! Extension Code !! Use\n|-\n| Text || .txt || text file, for stories, documents\n|-\n| Comma Separated Value || .csv || exported excel file, structured data, data from sensors, and numbers\n|}\n\nFirst, you need a file to read, so let\u2019s create a file.\n \nOpen the folder in which you wish to store the file. When right-clicking on an empty space, you are able to create a new file. Name it test_text.txt and open it. After that write something inside the file, save, and close it. Alternatively, you can also open the program that creates text files (for Windows 10 it is \"Notepad\") and create a new file by left-clicking on the file tab in the left corner and choosing \"New\" or press CTRL+N (both for Windows 10). After the file has been created, we can try to read from that particular file.\n\nTo read files from your computer to Python, there is a built-in function called \u201copen\u201d.\n\n<syntaxhighlight lang=\"Python\" line>\nfile = open(\"test_text.txt\")\n</syntaxhighlight>\nDon't forget that you have to specify the working directory when first opening the file. Before the \"test_text.txt\" (in the same quotation marks) you need to provide the file path so that Python knows where to find your text file\nNow, you can check if the file has been successfully read:\nFirst, you can read the file name:\n<syntaxhighlight lang=\"Python\" line>\nfile.name\n</syntaxhighlight>\n\nAnd then, of course, you can also check out the content of the file:\n<syntaxhighlight lang=\"Python\" line>\nprint(file.read())\n</syntaxhighlight>\nOnce you have finished your work with the file, we need to \u201cclose()\u201d the connection manually because the \u201copen()\u201d method uses some computer resources to clean up.\n\n<syntaxhighlight lang=\"Python\" line>\nfile.close()\n</syntaxhighlight>\n\n===WITH Statement===\nThe WITH statement is a python specific statement that manages and simplifies the opening and closing of files. Let's compare 2 codes:\n\n<syntaxhighlight lang=\"Python\" line>\n# code without WITH statement\nfile = open (\"test_text.txt\", \"r\")\nprint(file.read())\nfile.close()\n</syntaxhighlight>\n\n\n<syntaxhighlight lang=\"Python\" line>\n#code with WITH statement\nwith open (\"test_text.txt\", \"r\") as file:\n\t\tprint(file.read())\n</syntaxhighlight>\n\nWith the WITH statement, the close() method is automatically included. It also makes the code easier to read because of indentation.\n\n==Writing to Files==\nBesides just reading from the file, we can also write to a file.\n\n<syntaxhighlight lang=\"Python\" line>\nwr_file_ex = 'new_file.txt' # write file example\nwith open(wr_file_ex , \"w\") as writefile:\n    writefile.write(\"this is the first line \\\\n\")\n\t\twritefile.write(\"second line\\\\n\")\n</syntaxhighlight>\n\nThe code above will write 2 lines. Note that inside the \u201copen()\u201d method, we have to specify \u201cw\u201d (write) as an argument. In the very beginning, we have not specified any mode, which is why Python automatically used the reading mode. In the table at the end of this tutorial, you can find different modes you can use in Pyhthon.\n\nWe can also try to check what we have created:\n\n<syntaxhighlight lang=\"Python\" line>\nlines = [\"First line!\\n\", \"Second line!\\n\", \"Third line!\"]\n\nwith open(wr_file_ex, 'w') as writefile: \n\t\tfor line in lines: \n\t\t\t\twritefile.write(line)\n\n# and you can read the file using the read method\nwith open (write_file_ex, 'r') as read_file:\n\t\tprint(read_file.read())\n</syntaxhighlight>\n\nWarning: setting a file to mode \u201cw\u201d will overwrite all data inside.\n\n<syntaxhighlight lang=\"Python\" line>\nold_file = \"test_text.txt\"\nwith open (old_file,\"r\") as read_file: \n\t\tprint(read_file.read())\n# Write line to file\nwith open(old_file, \"w\") as write_file:\n    write_file.write(\"overwritten\\n\")\n\n# read again afterwards\nwith open (old_file,\"r\") as read_file: \n\t\tprint(read_file.read())\n</syntaxhighlight>\n\n==Appending==\nAs we know from the exercise above, writing overwrites all the old lines or data. Many times, we don't want the old data to be overwritten, and we just want to add a new line or new data. That\u2019s where appending comes in.\n\n<syntaxhighlight lang=\"Python\" line>\n# appending new lines to the old file\nold_file = \"test_text.txt\"\nwith open (old_file, 'a') as append_file: \n\t\tappend_file.write(\"another line\\\\n\")\n\t\tappend_file.write(\"another another line\\\\n\")\n\n# reading the file after new lines have been appended\nwith open (old_file, 'r') as read_appended_file: \n\t\tprint(read_appended_file.read())\n</syntaxhighlight>\n\n==Different modes when opening a file==\nHere is a table with the most important different modes when opening a file (we have covered almost all of them). Note that the last three are more advanced modes. They allow you to combine two different modes and you don't have to use the WITH statement whenever you want to combine two modes.\n\n{| class=\"wikitable\"\n|-\n! Statement !! Mode name !! Use\n|-\n| w || read mode || Overwriting files\n|-\n| r || write mode || Reading files\n|-\n| a || append mode || Adding new content to file\n|-\n| x || exclusive creation mode || Creating a new file and opening it for writing\n|-\n| r+ || reading and writing mode || Reading and writing, does not truncate file\n|-\n| w+ || writing and reading mode || Writing and reading, truncates file\n|-\n| a+ || appending and reading mode|| Creates new file if the file does not exist\n|}\n\n==Quiz==\n\n#  Try out a+ mode by running this:\n\n<syntaxhighlight lang=\"Python\" line>\n# quiz a+ mode\nwith open('Quiz.txt', 'a+') as write_file:\n    write_file.write(\"A whole new line\\n\")\n    print(write_file.read())\n</syntaxhighlight>\n\nCan you see the printed line? If not, then you\u2019re correct!\nThere is no error, but the \u201cprint()\u201d also does not output anything.\n\nTry it again with the r+ mode:\n\n<syntaxhighlight lang=\"Python\" line>\n# quiz r+ mode\nwith open('Quiz.txt', 'r+') as write_file:\n    write_file.write(\"A whole new line\\n\")\n    print(write_file.read())\n</syntaxhighlight>\n\nCan you now see the printed line?\nHow could you find out if you have written anything in the a+ mode?\n\n[[Category:Statistics]]\n[[Category:Python basics]]\n\nThe [[Table of Contributors|author]] of this entry is XX. Edited by Milan Maushart"
                    }
                ]
            },
            "1148": {
                "pageid": 1148,
                "ns": 0,
                "title": "Reference Manager: Zotero",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "{|class=\"wikitable\" style=\"text-align: center; width: 100%\"\n! colspan = \"4\" | Type !! colspan = \"4\" | Team Size\n|-\n|[[:Category:Me, Myself and I|Me, Myself and I]] || [[:Category:Group Collaboration|Group Collaboration]] || '''[[:Category:The Academic System|The Academic System]]'''  || '''[[:Category:Software|Software]]''' || '''[[:Category:Team Size 1|1]]''' || '''[[:Category:Team Size 2-10|2-10]]''' || '''[[:Category:Team Size 11-30|11-30]]''' || [[:Category:Team Size 30+|30+]]\n|}\n\n== What, Why & When ==\n'''What?'''<br>\nA reference manager is a software that automatically creates a list of references for you. Zotero is one of many possible managers (s. \"Other Software\").<br>\n'''Why?'''<br>\nReferences need to be in a consistent style and it can take a lot of time to make sure everything is cited correctly. A citation software guarantees a technically flawless list of references, thereby saving you both trouble and a lot of time.<br>\n'''When?'''<br>\nWhenever you write an academic text which needs referencing.\n\n== Goals ==\n* obtaining a flawlessly referenced text\n* saving time\n* avoiding cumbersome work\n* sharing literature with others\n\n== Setting It Up ==\n=== Installation ===\nYou can download Zotero via this website: https://www.zotero.org/download/ <br>\nIf you need help installing it, please refer to: https://www.zotero.org/support/installation <br> \nIf you face any difficulties, you can look for a step-by-step video on YouTube, depending on your operating system (Windows, macOS, Linux\u2026).<br>\nIf you would like to use the browser extension, you can get it here: https://www.zotero.org/download/connectors <br>\nI recommend using this extension since it allows you to grab literature more easily, especially if you do a lot of internet research.\n\n=== Overview of the Interface ===\n[[File:Zotero Interface Overview Frames.jpg|1000px|thumb|left|The Zotero Interface. Source: own.]]\n\nThere are four main elements in the Zotero interface you need to know at the beginning. <br>\n# On the left, you find your project structure.<br>\n# Using the symbols at the top, you can add literature to Zotero.<br>\n# The literature will appear in the central window, usually displaying title and author.<br>\n# The detailed information for a selected title appears in the right window (title, author, abstract, publisher, year, etc.)\n\n=== Folder Structure ===\n[[File:Zotero folder structure.png|thumb|right|Zotero folder structure. Source: own.]]\nZotero allows the creation of a hierarchical system of folders that contains the literature of your different projects. Please note that there is a difference between your personal library, in which you can store literature for your own projects, and group libraries, where multiple people have access to.\nWithin a library, you can create \u201ccollections\u201d and \u201csub-collections\u201d. I recommend having a collection for each project, for instance for a paper or for a group project you are working on. If it is a very large project, it may be useful to create sub-collections to have a clearer overview. If you like, you can go even further and create sub-collections of sub-collections and so forth.\n\n== Getting Literature In ==\nThere are essentially three ways to add references to Zotero.\n\n'''Adding by Identifier'''\n[[File:Zotero adding literature 1.png|400px|thumb|left|Adding Literature by Identifier. Source: own.]]\nThis is the most convenient and fail-safest way to add references. Published sources often have a digital identifier, for scientific journal articles it is the DOI and for books it is the ISBN. If you have a source at hand, whether it is an article you read online or a physical book in front of you, look for such identifiers and insert it in Zotero using the \u201cAdd Item(s) by Identifier\u201d-function\u201d, which looks like a magic wand.\n\nThe information obtained this way is usually correct and complete, so if you have a digital identifier at hand, this is your way to go.\n\n'''Using the Browser Extension''' <br>\nYou can grab references directly from the web, using the browser plugin. This is especially useful if you want to add a website as a source, which does not have a fixed digital identifier like a DOI or ISBN. But you can also add every other source type this way. \nEnter the website where your source is displayed and click on the Zotero-Connecter button. It will display a different symbol, depending on the source type (a book symbol for a book, a paper symbol for an article etc.). Next, you select the folder in which the source should be saved in, and you are done. <br>\n''Important hint'': If you add references automatically, you should always check in Zotero whether the imported information is correct. While information based on DOI or ISBN is usually quite reliable, there can be errors too. Especially information extracted from the web is error-prone and should be checked for face-validity.\n\n'''Adding References Manually'''\n[[File:Zotero adding literature 3.png|400px|thumb|left|Adding Literature Manually. Source: own.]]\nThis is necessary, for example, if you have a hard copy of an old book without any identifier or you are adding [[Glossary| grey literature]] that cannot be properly captured by the browser-plugin. <br>\nClick on the green \u201c+\u201d button and select the source type you would like to add. Depending on the source type, there will be slightly different categories showing up. For instance, if you add a journal article, you need to insert the journal name and volume, while for a video source, you need to put down its length and potentially a URL by means of which it can be accessed.\n\nAfter selecting a source type, a window on the right side of the screen will open. This is where you can enter all relevant information. Zotero will use this information later to create the reference list.\n<br>\n<br>\n<br>\n<br>\n<br>\n== Adding Literature to Your Document ==\n[[File:Zotero adding literature to Word 3.png|400px|thumb|right|Zotero Menu Bar in Word. Source: own.]]\n[[File:Zotero adding literature to Word 2.png|800px|thumb|right|Selecting a Reference Style. Source: own.]]\nZotero offers a plugin for Microsoft Word, Libre Office, and Google Docs, which makes it easier to use both for yourself and when working on shared documents. I will show the procedure for Microsoft Word, but it works the same for Google Docs.\n\n# Open Word. In the top bar, there is now a tab called \u201cZotero\u201d. Click on it.\n# I would suggest picking a reference style first. Select \u201cDocument Preferences\u201d. Now, you can select your preferred reference style.\n# If you already have some literature in your database, you can proceed to add an in-text-reference. Click on \u201cAdd/Edit Citation\u201d. A red bar appears where you can type in the author or title (or any other information) of the publication you would like to reference. Zotero will show you all publications from your library that match your search. Select the right title and it will appear as a rigid text box in the bar. You can click on the box to make slight changes, for instance to add page numbers. When you are satisfied, you can hit \u201center\u201d and the reference will be added to your text. This way, you can also add multiple references at once.\n# When you have added all your in-text-references, you can add the list of references at the end of your document. To do so, click on \u201cAdd/Edit Bibliography\u201d. You can also do this earlier in the process when not all references have been edited, since the reference list can be refreshed later using the \u201cRefresh\u201d button.\n\n[[File:Zotero adding literature to Word 4.png|1000px|thumb|center|Step 3.1]]\n[[File:Zotero adding literature to Word 5.png|1000px|thumb|center|Step 3.2]]\n[[File:Zotero adding literature to Word 6.png|1000px|thumb|center|Step 3.3]]\n\n== Other Software ==\nThis article only deals with the most basic functions of citation software \u2013 inserting in-text references and creating a list of references, that is. Depending on the software, there are many more features: reading and highlighting literature, drafting notes, building a structure for writing etc. Reference managers can also come in handy if you conduct a review study and need to handle a large number of publications.\n\nWhile there is other citation software (Citavi, Mendeley, EndNote\u2026), I present Zotero here because it works on Windows, Linux, and Mac. Furthermore, it is free to use up until a certain storage capacity. If you are a student, this storage space is likely to be sufficient. If you work or study at a university, check which software is provided by your institution.\n\n== Further Links ==\nThere is a plethora of videos on YouTube helping you with more specific issues regarding Zotero.\n\nZotero offers a FAQ as well as a forum for users: https://www.zotero.org/support/getting_help \n\nFor students of Leuphana university, the library team regularly offers workshops to introduce different citation programmes: https://www.leuphana.de/services/miz/service-support/miz-schulungsprogramm.html\n\n----\n__NOTOC__\n[[Category:Hacks, Habits & Tools]]\n[[Category:The Academic System]]\n[[Category:Software]]\n[[Category:Team Size 1]]\n[[Category:Team Size 2-10]]\n[[Category:Team Size 11-30]]\n\nThe [[Table_of_Contributors| author]] of this entry is Carlo Kr\u00fcgermeier."
                    }
                ]
            }
        }
    }
}