Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
crosscheckking
25,155 Points[Solved] Writing files to Desktop Windows
Hello again! I seem to be stumped. I'm trying (done with majority of it except anything Windows related it seems) to write a program that takes an excel file from a website, lets the user select the appropriate meeting from a dropdown read from the file, then lets the user swipe student ID cards, marks the students as attended, saves the file with a different name, and then brings the user to the webpage to upload the attendance upon completion. I used kivy to create the GUI. Everything works perfectly when I run it on OS X, but I run into a problem when I run it on Windows. Specifically, the problem is with saving the file to the Desktop. Now this isn't a huge problem because it'll save it to the Desktop automatically with my except statement that just relatively saves the file (and once the app is packaged using pyinstaller, it saves it with the app files which at least I know where it they are being saved). I have two try statements. The first tries to save it for a Mac, the second try statement tries to save it for Windows, and the second except after the second try fails just saves it in the same place as the python file (code posted below). This is my latest attempt, but I have also tried to use getpass.getuser() and that didn't work either. When I get the errors it usually says that it was looking for User\JohnLindsey, but Windows 10 is set up that it puts a space in the username that it makes using the Microsoft Account it seems, but these functions to get the User are returning it without a space. Any ideas? I put some screenshots I just took in here as well to help anyone understand the issue better. I'm trying to make this for a group and it would be passed on after I'm gone, so I need to it be able to work on OS X/ Windows for most any computer. (The code bellow has lines longer than suggested by PEP8, but for readability purposes I have kept it this way until I've fixed the problem).
try:
wb = openpyxl.load_workbook(os.path.expanduser('~/Desktop/' + dateCur + '_' + timeCur + '_bap_attendance.xlsx'))
except:
try:
wb = openpyxl.load_workbook(os.getenv('%HOMEPATH%') + '\\Desktop\\' + dateCur + '_' + timeCur + '_bap_attendance.xlsx')
except:
wb = openpyxl.load_workbook(
self.manager.get_screen('offline').ids.label3.text)
crosscheckking
25,155 Pointscrosscheckking
25,155 PointsI can't seem to upload the pictures by doing what's listed in the Markdown Cheatsheet (get a question mark in a box instead). But they basically just show that getpass.getuser() was return 'JohnLindsey' whereas I needed to type it with a space 'John Lindsey' to change to that directory.