omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Console output code

    Pythonista
    pythonista help
    6
    18
    14409
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • VIC3
      VIC3 last edited by VIC3

      Does anyone know the console output code?

      1 Reply Last reply Reply Quote 0
      • cook
        cook last edited by

        If you mean just printing to the console, use print

        print 'this will print in the console'
        
        VIC3 1 Reply Last reply Reply Quote 0
        • VIC3
          VIC3 @cook last edited by

          @cook no I mean like say you typed in a error into the console it'll say all of the red texted error I want the code for the output of the console (sorry if it confuses you)

          Webmaster4o 1 Reply Last reply Reply Quote 0
          • dgelessus
            dgelessus last edited by

            If you want to change the console's text color and such, look at Pythonista's console module docs.

            If you want to know how Python displays error messages and tracebacks, look at the CPython source code (https://github.com/python/cpython). The traceback module source might be easier to understand though since it's written in Python.

            1 Reply Last reply Reply Quote 0
            • Webmaster4o
              Webmaster4o @VIC3 last edited by

              @VIC3 It's still not clear at all what you mean.

              VIC3 2 Replies Last reply Reply Quote 2
              • VIC3
                VIC3 @Webmaster4o last edited by

                @Webmaster4o if you have some way of me contacting you I can send you a picture of what I mean

                1 Reply Last reply Reply Quote 0
                • ccc
                  ccc last edited by

                  @VIC3 Do you want to get the text that is printed to the console?

                  1 Reply Last reply Reply Quote 0
                  • dgelessus
                    dgelessus last edited by

                    @VIC3 The forum allows posting images. Upload your image to an image hosting site like http://imgur.com/, then insert it into your post using this syntax:

                    ![](http://your.image.url/goes/here/)
                    
                    1 Reply Last reply Reply Quote 0
                    • VIC3
                      VIC3 @Webmaster4o last edited by ccc

                      @Webmaster4o @ccc

                      Here take a look I typed the "/" at the top I want the code for the output (circled)

                      1 Reply Last reply Reply Quote 0
                      • dgelessus
                        dgelessus last edited by

                        @VIC3 It would help a lot if you could post the code that you ran. But it looks like you used pprint to print a tuple.

                        I'm still not sure what you mean with "the code for the output". You can just look at the source code of the script that you ran.

                        VIC3 1 Reply Last reply Reply Quote 1
                        • VIC3
                          VIC3 @dgelessus last edited by ccc

                          @dgelessus

                          # coding: utf-8
                          
                          import ui
                          from objc_util import *
                          import console
                          import os
                          import sys, traceback
                          
                          NSFileManager = ObjCClass('NSFileManager')
                          
                          UIDevice = ObjCClass('UIDevice')
                          
                          print 'Enter directory'
                          
                          path = raw_input()
                          
                          files = NSFileManager.defaultManager().contentsOfDirectoryAtPath_error_(path,None)
                          print files
                          
                          
                          @ui.in_background
                          def file_browser(message):
                          	alert_result=console.alert(path,path,'Dismiss',hide_cancel_button=True) 
                          
                          def back_console(sender):
                          	
                          	console.show_input()
                          	
                          @ui.in_background
                          def about(message):
                          	
                          	alert_result=console.alert('About', 'Project based off of Billy Ellis app called "iFiles" I take no credits for idea of this')
                          	
                          def find_ios(sender):
                          	
                          	vers = UIDevice.currentDevice().systemVersion()
                          	
                          	string = str(vers)
                          	
                          	v = sender.superview
                          	label = v['label1'].text = string
                          	
                          v = ui.load_view()
                          v.present('sheet')
                          
                          JonB 1 Reply Last reply Reply Quote 0
                          • dgelessus
                            dgelessus last edited by

                            If you want to get a list of all files in a folder, use os.listdir. It returns a normal Python list that you can work with as usual. There's no need to use objc_util for that.

                            1 Reply Last reply Reply Quote 1
                            • JonB
                              JonB @VIC3 last edited by

                              @VIC3
                              I think you need to use a few more words to explain your end goal!
                              You have used variations on "code for console output" a few times, and no one seems to know what you mean.... perhaps because your question might mean one of many things!

                              Code for console output might mean:

                              1. How can I write some text to the console?
                              2. How can I read what has already been written to the console?
                              3. How can I figure out which piece of code produced the output that I see in the console?
                              4. What code would I have to write to produce this specific output in the picture.

                              Do any of these summarize your question?

                              1 Reply Last reply Reply Quote 2
                              • cook
                                cook last edited by

                                @VIC3
                                Do you want to know how to take the list of files and use it in something like a tableview rather than just printing it in the console?

                                I assume that's something you want to do, since you're basing your app idea off of iFiles. But this part isn't coded in your script yet...also we don't know what your UI looks like...

                                VIC3 1 Reply Last reply Reply Quote 0
                                • VIC3
                                  VIC3 @cook last edited by ccc

                                  @cook Yes, exactly like iFiles by Billy Ellis here's the photo:

                                  1 Reply Last reply Reply Quote 0
                                  • cook
                                    cook last edited by

                                    @VIC3
                                    Alright I see. I've never used that app so I don't know! But anyway it's okay.

                                    Can you tell us this (just for clarity sake...):
                                    When you click on browser in your UI, please describe what you want to happen.

                                    VIC3 1 Reply Last reply Reply Quote 0
                                    • VIC3
                                      VIC3 @cook last edited by

                                      @cook I want it to have the file directory popup ever time I click browser but the only that I already have it to show what I'm typing in I just want it to read the console output it gives you in the alert

                                      1 Reply Last reply Reply Quote 0
                                      • cook
                                        cook last edited by

                                        @VIC3

                                        I think I'm still a little confused. But let's see if this is right:

                                        1. You start your script
                                        2. You type in a path (path)
                                        3. The UI comes up
                                        4. You want browser to show a file browser view using your path *(quick way would be a tableview) *

                                        If that's the case you first need to construct your data differently. You will need either a list or a dictionary to use for a tableview data source. Have you made a tableview before?

                                        Did you try os.listdir like @dglessus mentioned?

                                        Example:

                                        #os.listdir takes a path argument
                                        my_file_list = os.listdir('../Documents')
                                        

                                        Also: You could get path input from a console.input_alert() (a popup) rather than typing it into the console.

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post
                                        Powered by NodeBB Forums | Contributors