<#CDE799L1M|python> Is anyone facing issue in conv...
# python
h
#python Is anyone facing issue in converting output to string using str() or f"", i am getting error using both the option in latest pulumi version
g
can you show some example code?
h
@green-stone-37839 thanks for the response.
bucket = root_bucket.bucket.apply(lambda bk: f"{bk}")
isn't the
bucket
variable should be string but still it refer as output type
g
Works ok for me: o_bucket_name = my_bucket.bucket.apply(lambda bk: f”MyBucket:{bk}“) v3.100.0 on Mac(Sonoma 14.2.1)
h
Thanks @green-alligator-4238 for the reply. am using same mac and pulumi version as well. Are you able to print using print statement or log.info the
o_bucket_name
g
@hallowed-fireman-90476 - I can get basic text in log.info, but no luck yet with simply logging something as simple as a created bucket name…. I’m/We’re clearly missing something, but this is a real disappointment - why should this be so complicated…? Needing lambda for accessing computed data is bad enough, but why is a simple ‘print’ so difficult…?
Also very disappointed in the quality of error messages - very poor - no idea where the problem could be coming from…
Found it: o_bucket_name = my_bucket.bucket.apply(lambda bk: f”MyBucket:{bk}“) o_bucket_name.apply(lambda v: log.info(f”Log:{v}“)) • I the above ‘v’ can be used as / is a normal string value. • Output will be in the Diagnostics section Still getting my head around Pulumi concepts etc, but it looks like the bucket name comes from the provider/API, not from state, hence the need for the lambda call to go get the info (but I hope I’m wrong). Also, at a very high level, it would appear you ‘drive Pulumi with Python’ rather than write Python code that includes Pulumi, but again, hope I’m wrong - early days yet… In the above, o_bucket_name is an output object that needs to go get the bucket name via lambda, even though you’ve already done a lambda on the name - not the anticipated behaviour of a string of “MyBucket:${bucket_name}“. Good luck!
print() works the same way as log.info, but as an output at the end, as per normal Python.
h
@green-alligator-4238 i am also beginner to Pulumi, the combination of Output and Lambda in Python throws me off.