Welcome. The Modular forum has the ability to display code in mojo.
If you use three “ticks” and the word “mojo”, it will display your code correctly. Currently it is seeing the fn and then putting only that part in a code block.
For example:
```mojo
<Your code here>
```
returns
struct Table[dtype: DType=DType.float32]:
var data: UnsafePointer[Scalar[dtype]]
var rows: Int
var cols: Int
#var data_type: DType
fn __init__(out self, rows: Int, cols: Int):
self.rows = rows
self.cols = cols
#self.data_type = dtype
self.data = UnsafePointer[Scalar[dtype]].alloc(rows * cols)
fn datatype(self) -> DType:
return dtype
fn main():
tensor1 = Tensor[DType.uint8](10, 10)
print(tensor1.datatype())
Apologies for not having the answer to your code question.
The error when called from another file caller.mojo - I get is:
/tmp/checkout/caller.mojo:6:18: error: 'Tensor[float32]' value has no attribute 'datatype'
print(tensor1.datatype())# This does not work!
mojo: error: failed to parse the provided Mojo source module
My mojo version is: mojo 25.3.0.dev2025042205 (d893abbe)
It does work in the same file - but not when ‘Tensor’ struct is imported and called from another file(caller.mojo) - it throws up.