-3

When I was working with this code - sys.path is a list andits memebers are strings - but when used the below code, it is showing at 0x00B38C30>, please explain why?

Code :

import sys
print(x for x in sys.path)

sys.path is this

['C:\\Users\\eastwood\\OneDrive\\Python_Work\\Trials', 'C:\\Users\
\eastwood\\OneDrive\\Python_Work\\Trials', 'C:\\Users\\eastwood\\A
ppData\\Local\\Programs\\Python\\Python37-32\\python37.zip', 'C:\\
Users\\eastwood\\AppData\\Local\\Programs\\Python\\Python37-32\\DL
Ls', 'C:\\Users\\eastwood\\AppData\\Local\\Programs\\Python\\Pytho
n37-32\\lib', 'C:\\Users\\eastwood\\AppData\\Local\\Programs\\Pyth
on\\Python37-32', 'C:\\Users\\eastwood\\AppData\\Local\\Programs\\
Python\\Python37-32\\lib\\site-packages']

And

print(x for x in sys.path) 

gives <generator object <genexpr> at 0x00B38C30>

import sys
print(x for x in sys.path)

I was expecting the code to print the members of sys.path list!

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
eastwood4
  • 19
  • 4
  • 2
    Possible duplicate of [Python: print a generator expression?](https://stackoverflow.com/questions/5164642/python-print-a-generator-expression) – pmcarpan Jul 25 '19 at 04:55

1 Answers1

3

If you don't have any thing around the loop it's gonna be a generator, so use:

import sys
print([x for x in sys.path])
U13-Forward
  • 69,221
  • 14
  • 89
  • 114